I've been trying to have a animation punch that at the start does 2 damage but times it by the leaderboard stat called "Strength" but it keeps saying "ServerScriptService.Punch Damage:11:Attempt to index field 'LocalPlayer' (A nil value). It also makes a sound upon punch.
This script is in ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local sound = game.ServerStorage.Punch:Clone()
sound.Parent = char:WaitForChild("Head")
end)
end)
game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player, humanoid)
if humanoid.Health >= 10 then
humanoid.Health = humanoid.Health - 2 * game.Players.LocalPlayer.leaderstats.strength.Value
elseif humanoid.Health < 2 then
humanoid.health = 0
end
player.Character.Head.Punch:Play()
end)

1 comment
You can only use "LocalPlayer" from a client side local script, as it references the player that is on the client in which the local script is being run