Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the wall not appering when i touch the part?

So i am trying to make a wall appear if you have 20 (Tokens) or more But it dosent work. Idn if it is because im not actully accsessing the leaderstats

Code:

script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("leaderstats") and

hit.Parent.leaderstats.Tokens.Value >= 20 then

workspace.Wall.Transparency = 0

workspace.Wall.CanCollide = true

wait(0.5)

script.Parent:Destroy()

else

game.StarterGui.ScreenGui.Buy_Twenty_Tokens.Visible = true

end

end)

2 comments

0

Where do you store your leaderstats? It looks like you are searching for leaderstats inside the character and not the actual player. Since FindFirstChild returns nil since it can't find the leaderstats, it will just skip the rest.

0

How do you acsess the localplayer trough a regular script?

1 answer

✓ Accepted answer

I'll go with what @TheWaterFoox is saying. The leaderstats are usually placed inside of the player, not the player's Character. To get the player, simply use GetPlayerFromCharacter():

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
	    if player:FindFirstChild("leaderstats").Tokens.Value >= 20 then
		    workspace.Wall.Transparency = 0
		    workspace.Wall.CanCollide = true
			wait(0.5)
		    script.Parent:Destroy()
	    end
    end
end)

As for editing your GUI, I would recommend using a LocalScript.

This discussion is preserved as it was. New answers, comments, and votes are closed.