I am doing my own health system for my game and I am having trouble with decrasing a player's HP. This script is in the part that you need to touch to decrease HP.
debounce = false
function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then
if not debounce then
if script.Parent.Name == "Ball" then
debounce = true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.HP.Value = plr.leaderstats.HP.Value-1
wait(5)
debounce = false
end
end
end
end
script.Parent.Touched:Connect(onTouched)
It works in roblox studio but not in the real game. Everything is in the place it should be and have these names. In the game, it returns: "leaderstats is not a valid member of player" (line 9)
Thanks

13 comments
In the player that touched the part doesn't have any direct descendants that are called "leaderstats" so that errors
Can you tell me where leaderstats is inside the player (example: plr.PlayerGui.leaderstats)
But I have another script that creates a Folder inside the player with that name. Also the leaderstats are showing in the player list, but not changing when touching it
game.Players.(player).leaderstats
can You give me the code of the other script that adds the script?
local plr = game.Players.LocalPlayer local leader = Instance.new("Folder") leader.Name = "leaderstats" leader.Parent = plr
Do you have FilteringEnabled on?
How do I check that? Sorry Im new at roblox scripting
Go in workspace properties. Scroll down until you see "FilteringEnabled" Tell me if it has a check mark next to it.
Yes it is activated
Ok. I'll answer you
Ok. Thanks!
You can use remote event/functions