THANK YOU ALL SO MUCH FOR 100 SUBS! I'll try to respond to all of your comments and give help/feedback to everyone who needs it. Write your issues in the comments and I'll help!
local Runservice = game:GetService("RunService") local uis = game:GetService("UserInputService") local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local camera = workspace.CurrentCamera local mouse = player:GetMouse() local viewmodel = game.ReplicatedStorage.Viewmodel local currentVM = nil local idle = true local walking = false local loadedAnims = { idle = nil, walking = nil } local swaycf = CFrame.new() local lastcameracf = CFrame.new() local sound = workspace["Flashlight Switch Plastic Slides On Off 15 (SFX)"] local function loadSlot(weapon) if weapon then if camera:FindFirstChildWhichIsA("Model") then camera:FindFirstChildWhichIsA("Model"):Destroy() currentVM = nil end local newVM = viewmodel:Clone() newVM.Parent = camera currentVM = newVM sound:Play() --loading animations loadedAnims.idle = newVM.Humanoid:LoadAnimation(newVM.Animations.Idle) loadedAnims.walking = newVM.Humanoid:LoadAnimation(newVM.Animations.Walk) end end Runservice.RenderStepped:Connect(function() if character then if currentVM then local rot = camera.CFrame:ToObjectSpace(lastcameracf) local x,y,z = rot:ToOrientation() swaycf = swaycf:Lerp(CFrame.Angles(math.sin(x) * 0.7, math.sin(y) * 0.7, 0), 0.1) lastcameracf = camera.CFrame
local bobx local boby
if walking then bobx = math.sin(time(0) * 9)/20 boby = math.cos(time(0) * 8 * 2)/20 elseif idle then bobx = math.sin(time() * .75)/120 boby = math.cos(time() * .75 * 2)/120 end
local finalbob = CFrame.new(bobx, boby, 0) currentVM:SetPrimaryPartCFrame(camera.CFrame * swaycf * finalbob) end end end) character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function() if currentVM then if character.Humanoid.MoveDirection.Magnitude > 0 then walking = true idle = false end if character.Humanoid.MoveDirection.Magnitude == 0 then walking = false idle = true end end end) uis.InputBegan:Connect(function(input, gamepro) if gamepro then return end if input.KeyCode == Enum.KeyCode.F then loadSlot(viewmodel) else if input.KeyCode == Enum.KeyCode.R then if currentVM then currentVM:Destroy() currentVM = nil sound:Play() end end end end)
this should be easy! all you need to do is hook up a tool to the equip system. if you need help i might be able to help make a small change in your code for you!
my script does not work here it is local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local player = game.Players.LocalPlayer local character = player.Character or player.Character:Wait() local camera = workspace.CurrentCamera local mouse = player:GetMouse() local viewmodel = game.ReplicatedStorage.ViewModels local currentVM = nil local idle = true local walking = true local shooting = false local fullautoshooting = false local inair = false local canshoot = true local can reload = true local reloading = false local loadedanims = { shoot = nil reload = nil inspect = nil } local inventory { primary "" secondary "Deagle" knife "" module = nil } local swaycf = CFrame.new() local lastcameracf = CFrame.new() local function cancelreload()
end local function loadslot() if weapon then if camera:FindFirstChild("Model") then currentVM:Destroy() currentVM = nil end if not viewmodel:FindFirstChild(weapon) then warn("cant find wepon in folder") return end local newVm = viewmodel:FindFirstChild(weapon):Clone() newVm.Parent = camera currentVM = newVm inventory.module = require(currentVM.Module)
end RunService.RenderStepped:Connect(function() if check character then if cameraVM then local rot = camera.CFrame:ToObjectSpace(lastcameracf) local x,y,z = rot:ToOrientation()
if walking and not inair then bobx = math.sin(time() * 7.5)/20 boby = math.cos(time() * 7.5 * 2)/20 elseif idle and not inair then bobx = math.sin(time() * 7.5)/120 boby = math.cos(time() * 7.5 * 2)/120 elseif inair then bobx = 0 boby = 0 end
local Cframebob = CFrame.new(bobx, boby, 0) currentVM:SetPrimaryPartCframe(camera.CFrame * swaycf * Cframebob) end end end) UserInputService.InputBegan:Connect(function(input, gamepro)) if gamepro then return end if input.KeyCode == Enum.KeyCode.One then loadslot(inventory.primary) end UserInputService.InputBegan:Connect(function(input, gamepro)) if gamepro then return end if input.KeyCode == Enum.KeyCode.Two then loadslot(inventory.secondary) end
THANK YOU ALL SO MUCH FOR 100 SUBS! I'll try to respond to all of your comments and give help/feedback to everyone who needs it. Write your issues in the comments and I'll help!
Please help
Hey I had recently discovered that my gun doesn't do any damage. Please help, Thanks
YK its hard being a scripter when u need a plugin for motivational texts.
Icl you are very underrated bro, please continute this!
Edit: Everything works btw
@@rman_n thank you🙏 im glad everything works
@@sqood652It didn’t kill the dummy
Good tutorial. Thank you.
naaahh thank ya bro really
ill follow the tutorial
damn make a video on about that math things, thats actually cool
First
yo yo where is that pistol model
Moon Animator doesn't recognise the viewmodel as a rig can you help me? EDIT: nvm I figured out the issue
Hey I was wondering if there would be a recoil system in next tutorial? If not totally fine! good stuff
@@rman_n love the idea! this actually isnt too hard so ill add it to the next tutorial
@@sqood652 Alright no problem! looking forward to it
can you make a tut with blender animation instead of moon cuz i dont have 20 dollars
how do i fix the viewmodel not showing up when i press two and its not giving me errors when i press one its not telling me anything
yo, my camera is bugged
my viewmodel is for a flashlight, so the script is kinda short
can i see the script?
Alright
Hold on
local Runservice = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local viewmodel = game.ReplicatedStorage.Viewmodel
local currentVM = nil
local idle = true
local walking = false
local loadedAnims = {
idle = nil,
walking = nil
}
local swaycf = CFrame.new()
local lastcameracf = CFrame.new()
local sound = workspace["Flashlight Switch Plastic Slides On Off 15 (SFX)"]
local function loadSlot(weapon)
if weapon then
if camera:FindFirstChildWhichIsA("Model") then
camera:FindFirstChildWhichIsA("Model"):Destroy()
currentVM = nil
end
local newVM = viewmodel:Clone()
newVM.Parent = camera
currentVM = newVM
sound:Play()
--loading animations
loadedAnims.idle = newVM.Humanoid:LoadAnimation(newVM.Animations.Idle)
loadedAnims.walking = newVM.Humanoid:LoadAnimation(newVM.Animations.Walk)
end
end
Runservice.RenderStepped:Connect(function()
if character then
if currentVM then
local rot = camera.CFrame:ToObjectSpace(lastcameracf)
local x,y,z = rot:ToOrientation()
swaycf = swaycf:Lerp(CFrame.Angles(math.sin(x) * 0.7, math.sin(y) * 0.7, 0), 0.1)
lastcameracf = camera.CFrame
local bobx
local boby
if walking then
bobx = math.sin(time(0) * 9)/20
boby = math.cos(time(0) * 8 * 2)/20
elseif idle then
bobx = math.sin(time() * .75)/120
boby = math.cos(time() * .75 * 2)/120
end
local finalbob = CFrame.new(bobx, boby, 0)
currentVM:SetPrimaryPartCFrame(camera.CFrame * swaycf * finalbob)
end
end
end)
character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if currentVM then
if character.Humanoid.MoveDirection.Magnitude > 0 then
walking = true
idle = false
end
if character.Humanoid.MoveDirection.Magnitude == 0 then
walking = false
idle = true
end
end
end)
uis.InputBegan:Connect(function(input, gamepro)
if gamepro then return end
if input.KeyCode == Enum.KeyCode.F then
loadSlot(viewmodel)
else
if input.KeyCode == Enum.KeyCode.R then
if currentVM then
currentVM:Destroy()
currentVM = nil
sound:Play()
end
end
end
end)
Could you make a tutorial on how to make these weapons tool-based? Thanks!
this should be easy! all you need to do is hook up a tool to the equip system. if you need help i might be able to help make a small change in your code for you!
@@sqood652yes, that would be very helpful!
@@sqood652 how do i do that
@@TheRealOvenRoasted shoot!! i forgot about this😭😭 ill start working on the changed rn
@@sqood652 lol its alright
How would you add bullet effects?
I think that will be added in another tutorial
@@rman_n alright
Pls make part 2
whenever the character dies, the view model lays on the floor and does not get deleted, do you know why?
why?
@@bbhoosnse7148 it was actually a problem with my camera getting disconnected from the player model.
my fullauto if i just do one click it just starts shooting without me clicking.
The rest works btw thx!
make sure you turn off your full auto bool value when u let go of left click
Why does he have less than a mil subs
yoo can you make more features like changing weapon and a ui?
maybe next tutorial!
@@sqood652 ok i can't wait for the next tutorial
@@sqood652 Please do make it!!!
wait can the server see how the client is holding the gun?
no they cant. if you want, ill add that into the next tutorial
@@sqood652 alright
hi sean!!
This script works just as expected and it looks awesome! I have just one issue. How can I make it so that you can see other's viewmodels?
@@DOOM-mm6hq ill have that working in the next tutorial! stay tuned
im glad everything work as it should :)
when u upload next gun tutorial lol
in a bit 😭 im working on a devlog rn
@@sqood652 oh didn't realize lol! My bad
@@Retro_qe0982 nah ur good u didnt know
@@sqood652 if u will make an ep3 for this can u do the bug fixes on that part?
@@Retro_qe0982 gotchu
I don't know why I'm encountering this problem but after I added canshoot = true I still can't shoot the gun after the first, please help
@@Blacky8111 make sure you have canshoot enabled when u try shooting
Okay
Just got it to work, there was a problem with the spread function
Only problem is my gun doesn’t do damage
Great tutorial, as an intermediate scripter I can hardly remember all the objects and commands. Thanks
for me the model that i am using is not being animated... I made the Bolt a motor 6d, but it is not working in Moon Animator.
@@aquzr5630 is it anchored? make sure it isnt!
@@sqood652 the gun isn't anchored
@@sqood652 it is anchored
@@aquzr5630 😭😭if it still doesnt work then make sure your making the part 1 of the motor 6d the handle of the gun and u should be all set :)
@@sqood652 what do you mean?
please someone give me the script i been working on this shi# for a week now its still not working
bruh i so lazy to do code
i need copy
bruh
@@Retro_qe0982 what?
@@Helloiamisbruhpro bruh
bruh
w
my script does not work here it is
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()
local viewmodel = game.ReplicatedStorage.ViewModels
local currentVM = nil
local idle = true
local walking = true
local shooting = false
local fullautoshooting = false
local inair = false
local canshoot = true
local can reload = true
local reloading = false
local loadedanims = {
shoot = nil
reload = nil
inspect = nil
}
local inventory {
primary ""
secondary "Deagle"
knife ""
module = nil
}
local swaycf = CFrame.new()
local lastcameracf = CFrame.new()
local function cancelreload()
end
local function loadslot()
if weapon then
if camera:FindFirstChild("Model") then
currentVM:Destroy()
currentVM = nil
end
if not viewmodel:FindFirstChild(weapon) then warn("cant find wepon in folder") return end
local newVm = viewmodel:FindFirstChild(weapon):Clone()
newVm.Parent = camera
currentVM = newVm
inventory.module = require(currentVM.Module)
loadedanims.shoot = newVm.Humanoid:loadanimation(newVm.Animations.Shoot)
loadedanims.reload = newVm.Humanoid:loadanimation(newVm.Animations.reload)
loadedanims.inspect = newVm.Humanoid:loadanimation(newVm.Animations.Inpect)
end
end
local function reload()
end
local function spread()
end
local function shoot()
end
RunService.RenderStepped:Connect(function()
if check character then
if cameraVM then
local rot = camera.CFrame:ToObjectSpace(lastcameracf)
local x,y,z = rot:ToOrientation()
swaycf:Lerp(CFrame.Angles(math.sin(x) * 3, 0), 0.05)
local bobx
local boby
if walking and not inair then
bobx = math.sin(time() * 7.5)/20
boby = math.cos(time() * 7.5 * 2)/20
elseif idle and not inair then
bobx = math.sin(time() * 7.5)/120
boby = math.cos(time() * 7.5 * 2)/120
elseif inair then
bobx = 0
boby = 0
end
local Cframebob = CFrame.new(bobx, boby, 0)
currentVM:SetPrimaryPartCframe(camera.CFrame * swaycf * Cframebob)
end
end
end)
UserInputService.InputBegan:Connect(function(input, gamepro))
if gamepro then return end
if input.KeyCode == Enum.KeyCode.One then
loadslot(inventory.primary)
end
UserInputService.InputBegan:Connect(function(input, gamepro))
if gamepro then return end
if input.KeyCode == Enum.KeyCode.Two then
loadslot(inventory.secondary)
end
@@D3CST what part doesnt work? it might be because you forgot to do an equal in the inventory for your weapons.
@@sqood652 what do you mean
@@D3CST under the inventory table, it says primary "". did you forget the equal sign?
@@sqood652 oh where
@@D3CST the inventory