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

[ANSWERED] Why isn't Player a valid value in my button?

I'm trying to make a teleport button that only lets you teleport if you have a certain amount of money on the leader board but there's an error on line 7 Player isnt a valid value, any help?

Here's my script:

function onClicked() local p = game.Players:GetChildren() for i = 1, #p do

if player.leaderstats.Money.Value > 1 then --player in this line wasnt valid, can someone explain why? im still new

end h.Parent.Torso.CFrame = CFrame.new(Vector3.new(281, 30.6, -26))

end end end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 answers

✓ Accepted answer

"player" is not defined. Make it a value by doing:

local player = 
--or
player = 

###Well, since you want one player to teleport, you shouldn’t use a for loop. ###It says "player is not a valid member" because you didn’t define it in any way, you just used it in your script with no context.

###The ClickDetector.MouseClick event passes the player as a parameter, so this makes it easy.

-- Server Script inside part
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if plr.leaderstats.Money.Value > 1 then
        plr.Character.HumanoidRootPart.CFrame = CFrame.new(281, 30.6, -26)
    end
end)

1 comment

0

Thanks for clarifying, sorry im new.

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