So i have a tool, and if you click, it swings and does damage, but if you press F, it only work in studio test mode. Could anyone help?
script.Parent.Equipped:connect(function(mouse)
print("Equipped")
mouse.KeyDown:connect(function(key)
if key=="f" then
print("Keydowned")
local char=script.Parent.Parent
local plr=game.Players:GetPlayerFromCharacter(char)
script.Parent.GripUp=Vector3.new(-1, 5, -0)
a=Instance.new("Part")
a.Parent=game.Workspace
b=Instance.new("PointLight")
b.Parent=a
b.Range=20
if plr.TeamColor==BrickColor.new("Bright yellow") then
b.Color=Color3.new(255/255, 239/255, 5/255)
elseif plr.TeamColor==BrickColor.new("Dark green") then
b.Color=Color3.new(25/255, 144/255, 17/255)
end
a.CanCollide=false
a.Transparency=.4
a.BrickColor=BrickColor.new("Bright yellow")
a.Shape="Ball"
a.Size=Vector3.new(.5,.5,.5)
a.Position=script.Parent.Gun.Position
a.Velocity=script.Parent.Parent.Head.CFrame.lookVector*math.random(300,500)
script.Parent.GripUp=Vector3.new(-1, 0.01, -0)
--add playercheck
--add movement-Check
--add color depending on team
--kthx
debounce2=false
a.Touched:connect(function(hit)
if hit.Name==script.Parent.Parent.Parent.Name then
if debounce2==false then
debounce2=true
if hit.ClassName=="Hat" then
debounce=false
elseif hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(100)
wait(2)
debounce=false
else
wait(2)
debounce=false
end
end
end
end)
end
end)
end)

3 comments
Its in a normal script. I added the wait, and it didn't work, and I didn't think it would.
It works if thats a LocalScript.
You need to use a LocalScript because you are taking commands from the client. Try that and use the wait. It will work.