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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

local player = 
--or
player = 
Ad
Log in to vote
0
Answered by 5 years ago

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)
0
Thanks for clarifying, sorry im new. Pr_ogram 17 — 5y

Answer this question