Punch script only effects anything on local players screen?
I have attempted to fix it myself by putting it into a server script and testing outside of studio but im stumped currently.
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
07 | Mouse.Button 1 Down:Connect( function () |
09 | local character = Player.Character |
10 | local hitbox = character:FindFirstChild( "RightHand" ) |
11 | local humanoid = character:FindFirstChild( "Humanoid" ) |
12 | local animation = Instance.new( "Animation" ) |
14 | local animation 2 = Instance.new( "Animation" ) |
16 | local animation 3 = Instance.new( "Animation" ) |
18 | local animpick = math.random( 1 , 3 ) |
20 | local animTrack = humanoid:LoadAnimation(animation) |
25 | elseif animpick = = 2 then |
26 | local animTrack = humanoid:LoadAnimation(animation 2 ) |
31 | elseif animpick = = 3 then |
32 | local animTrack = humanoid:LoadAnimation(animation 3 ) |
39 | hitbox.Touched:Connect( function (hit) |
40 | if hit.Parent = = character:FindFirstChild( "RightHand" ) then |
46 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
47 | if humanoid and enabled = = true then |
49 | humanoid.Health = humanoid.Health - Player.leaderstats.Power.Value |
50 | Player.leaderstats.Power.Value = Player.leaderstats.Power.Value + 1 |
54 | elseif humanoid = = false and enabled = = true then |
56 | Player.leaderstats.Power.Value = Player.leaderstats.Power.Value + 1 |
What the code is supposed to do is have the character run an animation and see if the right hand hits anything if it hit a humanoid it does damage. It seems to work on the surface but when i test it with multiple players it only changes anything on that players screen. Even if i kill someone they only appear dead on my screen vice versa.
The code is in a local script in StarterGui
I would greatly appreciate for someone to help find the errors in the script