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)
LocalScripts run their methods at different times than normal Scripts, which can mess things up. It works in Test Mode because all scripts run locally on Test Mode. All you have to do is add a short wait at the beginning of your script and it should fix. Ex:
wait(1) -- Script here.