debounce = 0
script.Parent.Activated:Connect(function(mouse)
if debounce == 0 then
debounce = 1
if mouse.Target ~= nil then
if mouse.Target.Parent:findFirstChild("Humanoid") ~= nil and mouse.Target.Name ~= "Head" then
mouse.Target.Parent.Humanoid:TakeDamage(100)
elseif mouse.Target.Parent.Parent:findFirstChild("Humanoid") ~= nil then
mouse.Target.Parent.Parent.Humanoid:TakeDamage(100)
elseif mouse.Target.Name == "Head" then
mouse.Target.Parent.Humanoid:TakeDamage(100)
end
end
script.Parent.Hole.Flash.Enabled = true
script.Parent.GripUp = Vector3.new(0,1,-0.1)
wait(0.1)
script.Parent.Hole.Flash.Enabled = false
script.Parent.GripUp = Vector3.new(0,1,0)
wait(0.9)
debounce = 0
end
end)
This script is either running on the server or the client (Script or LocalScript). Either way, there’s a few mistakes related to this.
You’d only want to use the mouse object and properties such as mouse.Target on the client.
Secondly, you’d only want to deal damage on the server. How else would the damage replicate?
A gun script, since it requires both input and damage, needs work on both sides of the client-server boundary. You may want to consider sending a RemoteEvent to the server from the client telling the server to deal the damage. You may also want to consider sanity checks to make it less exploitable.
debounce = 0
function equipped(mouse)
function Shoot()
if debounce == 0 then
debounce = 1
if mouse.Target ~= nil then
if mouse.Target.Parent:findFirstChild("Humanoid") ~= nil and mouse.Target.Name ~= "Head" then
mouse.Target.Parent.Humanoid:TakeDamage(50)
elseif mouse.Target.Parent.Parent:findFirstChild("Humanoid") ~= nil then
mouse.Target.Parent.Parent.Humanoid:TakeDamage(50)
elseif mouse.Target.Name == "Head" then
mouse.Target.Parent.Humanoid:TakeDamage(50)
end
end
script.Parent.Hole.Flash.Enabled = true
script.Parent.GripUp = Vector3.new(0,1,-0.1)
wait(0.1)
script.Parent.Hole.Flash.Enabled = false
script.Parent.GripUp = Vector3.new(0,1,0)
wait(0.9)
debounce = 0
end
end
mouse.Button1Down:connect(Shoot)
end
script.Parent.Equipped:connect(equipped)