I’m making an fps game for fun, and I ran into this problem. my gun is a mesh, and I have it welded in my hand. it is inside the character but its a local script when I check the gun the local script is gone here is my local script:
localscript inside the gun
local plrs = game.Players
local reps = game.ReplicatedStorage
local plr = plrs.LocalPlayer
local mouse = plr:GetMouse()
local gun = script.Parent
mouse.Button1Down:Connect(function()
if mouse.Target ~= nil then
reps.Shoot:FireServer(mouse.Hit.Position, false)
else
reps.Shoot:FireServer(mouse.Hit.Position, true)
end
end)
serverscript in scs
local plrs = game.Players
local reps = game.ReplicatedStorage
local tws= game:GetService("TweenService")
local gunrange = 500-- in studs
reps.Shoot.OnServerEvent:Connect(function(plr,mousepos,target)
local gun = plr.Character:FindFirstChild('Gun')
local dmg = gun.Damage.Value
if gun == nil then end
local direction = (mousepos - gun.ShootPart.Position) * gunrange
local ray = RaycastParams.new()
ray.FilterDescendantsInstances = {plr.Character}
ray.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(gun.ShootPart.Position, direction, ray)
local bullet = reps.Bullet:Clone()
bullet.CFrame = gun.ShootPart.CFrame
bullet.Parent = workspace
local bduration = 0.3 * ((direction/gunrange).Magnitude)/50
tws:Create(bullet, TweenInfo.new(bduration), {CFrame = CFrame.new(mousepos)}):Play()
if not target then
task.delay(bduration, function()
bullet:Destroy()
end)
else
task.delay(1, function()
bullet:Destroy()
end)
end
if result == nil then return end
local hum = result.Instance.Parent:FindFirstChild("Humanoid")
if hum == nil then return end
task.wait(bduration)
hum.Health -= dmg
end)
It’s good that you found the solution, however, unless your game is in a really nieche scenario, you should make it a tool, and put the local script in it, then put it in starterpack if you need players to spawn in with it.
You can use a plugin like Tool Grip Editor to adjust the grip so you hold it right. you don’t need to weld it to your hand.
I think that plugin costs 100 robux though, you could use this free version with 1,000+ likes, I just checked it out and it appears to be safe, and it works about the same just not as nice, and missing some QOL.
You don’t need to grab the mouse and detect when it’s clicked, you can simply use Tool.Activated() and place all the logic in that connection, that runs whenever the player clicks while holding the tool
yes I have tried that exact thing but when I played running animations it made my right arm hold the tool and made my left arm do the animation how I fix it?
Do you use moon animator or the default roblox animator?
If you use the default, somewhere around the save tab it should show a button called Change Animation Priority, set it to movement.
you should not need to animate with the gun at all as long as the gun itself isn’t playing any animations, if you have the gun set to play animations set those to action and it will override the running animation, so I suggest you only animate the arms for aiming the gun, nothing else. You do not need to animate the legs or torso.
If you use moon animator, just press file and change it from there.
Okay basically this is what your animations should be:
For running, you can just set it to movement, you can animate any limbs, limbs you do not animate will have other animations of higher or the same priority animate them if there are multiple animations all at once.
For aiming, you only need to animate the arms, either one arm or both, if you want to animate the legs and torso, I am gonna assume you are trying to make an aiming animation where you stand still, if that is the case you can use code to play the animation for aiming while standing still and else just play the normal aiming animation.
Running should be priority Movement, Aiming should be Priority Action.
You do not need to animate the running animation with the gun, it will override the gun as long as you are animating the arm the gun is supposed to be in.