Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix server side damage script?

Asked by 4 years ago

Im trying to make it so when you punch you deal damage, i have the local script i just need help with the server script to send the damage to the server but i have no idea on what im doing.

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2local Punch = ReplicatedStorage:WaitForChild("Punch")
3local player = game.Players.LocalPlayer
4local str = player.leaderstats.strength
5 
6Punch.OnServerEvent:Connect(function(player)
7    player.Parent.Humanoid:TakeDamage(str)
8end)

This is what i have so far, im getting the error "attempt to index nil with 'leaderstats' i want to make it so the more strength you have that's the amount of damage you do so if u earned 100 strength you do 100 damage, etc.

0
i can't really help with the index nil with leaderstats thing but i do think i see something else, on local str = player.leaderstats.strength you should add .Value to the end of it so it can be assigned to the value of strength and not just the variable strength yasquerda 32 — 4y
0
I got the same error, is there another way i can get the players stats? ItzSulfonic 61 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

If the script you put is the server script, you can't access LocalPlayer from a serverside script. Has to be called from a local script only. Alternative way of getting the player is game.PlayerAdded

Ad
Log in to vote
1
Answered by 4 years ago

Thanks for the help, i've gotten it now heres the updated script

1game.Players.PlayerAdded:Connect(function(player)
2 
3end)
4 
5game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player, humanoid)
6    local str = player.leaderstats.strength.Value
7    humanoid:TakeDamage(str)
8end)
0
You should insert the "OnServerEvent" function inside the "PlayerAdded" function as well Omq_ItzJasmin 666 — 4y

Answer this question