script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local tokeeen = hit.Parent:WaitForChild("leaderstats").Tokens
tokeeen.Value = tokeeen.Value + 1
end
end)
Then I get infinite yield in output
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local tokeeen = hit.Parent:WaitForChild("leaderstats").Tokens
tokeeen.Value = tokeeen.Value + 1
end
end)
Then I get infinite yield in output
This happens because hit.Parent is the Character of the player and leaderstats is in the Player object, not the character.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local tokeeen = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).leaderstats.Tokens
tokeeen.Value = tokeeen.Value + 1
end
end)
----------EXPLANATION----------
I'm just gonna explain the code I added in. So, I get the PlayersService and use the function GetPlayerFromCharacter this function is self-explanatory, it just gets the Player from the Character. In the parameter is hit.Parent. hit.Parent is the character model of the Player. So, once I got the player, I define the leaderstats then the Tokens.
try
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local tokeeen = game.Players[hit.Parent.Name].leaderstats.Token
tokeeen.Value = tokeeen.Value + 1
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.