Here's the code, is there any problem with this code?
local plr = game.Players.LocalPlayer local CanDamagePlayers = true local damage = 32 script.Parent.Top.Touched:connect(function(p) if p.Parent:FindFirstChild("Humanoid") and CanDamagePlayers == true and p.Parent.Humanoid.Health > 0 then p.Parent.Humanoid:TakeDamage(damage) script.Parent.Sound:Play() plr.leaderstats.Pins.Value = plr.leaderstats.Pins.Value + 12 CanDamagePlayers = false wait(1) CanDamagePlayers = true end end)
Assuming that is in a server script, you cannot get the LocalPlayer from the server in actual game servers. This is because LocalPlayer is used only to get the player who has ownership of a local script.
If this is a server script inside a tool, you should be able to convert it to a local script and it should work (as tools are individual to the owner and thus allows you to run local scripts within them)
However, if you have filtering enabled, the leaderstats will not be properly added and the damage would not be properly dealt if it was run from a local script (it would only occur for that client)
Because of this, something like this might work better in a server script:
local CanDamagePlayers = true local Damage = 32 script.Parent.Top.Touched:connect(function(p) if p.Parent:FindFirstChild("Humanoid") and CanDamagePlayers == true and p.Parent.Humanoid.Health > 0 then p.Parent.Humanoid:TakeDamage(damage) script.Parent.Sound:Play() local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent) plr.leaderstats.Pins.Value = plr.leaderstats.Pins.Value + 12 CanDamagePlayers = false wait(1) CanDamagePlayers = true end end)
Bear in mind this is assuming the script is inside a tool, and that the tool has a part called Top inside.