Hi,
I am trying to set and get a leaderstat value from a server script but having issues getting the local player, I cant do it from part touch and can’t figure out how to do it.
Hi,
I am trying to set and get a leaderstat value from a server script but having issues getting the local player, I cant do it from part touch and can’t figure out how to do it.
If you wish to set and get a leaderstat value when a player’s character touches a part, simply use
When the part you want to trigger the change in the leaderstat value is touched, just check if there is a part.Parent:FindFirstChild(“Humanoid”). If so, use
local player = Players:GetPlayerFromCharacter()
to get the player from the character. Next, just do player.leaderstats.[Value_here] and you’re done! ![]()
You can’t get the localplayer from a serverscript. You’d have to do something like
workspace.Part.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then -- the value can be anything u want
player.leaderstats:FindFirstChild("WHATEVER YOUR VALUE IS NAMED").Value = 10
end
end)