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 3 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.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Punch = ReplicatedStorage:WaitForChild("Punch")
local player = game.Players.LocalPlayer
local str = player.leaderstats.strength

Punch.OnServerEvent:Connect(function(player)
    player.Parent.Humanoid:TakeDamage(str)
end)


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 — 3y
0
I got the same error, is there another way i can get the players stats? ItzSulfonic 61 — 3y

2 answers

Log in to vote
1
Answered by 3 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 3 years ago

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

game.Players.PlayerAdded:Connect(function(player)

end)

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

Answer this question