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)
You can't mention LocalPlayer in a ServerScript, as it is not client sided. Insead, use this:
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 * player.leaderstats.strength.Value elseif humanoid.Health < 2 then humanoid.health = 0 end player.Character.Head.Punch:Play() end)