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

Infinite in output but the script is correct and I get problems in output?

Asked by 3 years ago
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

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question