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

Why cant my Shop script locate the Value of the Price?

Asked by 5 years ago
Edited 5 years ago

my player is defind here since i couldnt figure out how to find local player in a normal script

game.Players.PlayerAdded:Connect(function(player)
    local price = player.PlayerGui:WaitForChild("Gui").Main.Info.Price
    local leaderstats = player:FindFirstChild("leaderstats")
    local Cash = leaderstats:FindFirstChild("Cash")

    if Cash.Value >= price.Value then
    Cash.Value = Cash.Value - price.Value

The "price" is a intValue. When I did

local price = 100

it worked. But when i changed it back to

local price = player.PlayerGui:WaitForChild("Gui").Main.Info.Price

it didnt work. This is all in a normal script in workspace. Can someone explain why my script cant find the value of the "price" The "price" is located in the Gui

0
Is the ouput saying something like cannot locate an object User#25068 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Servers don't usually have access to anything in a player's PlayerGui, so when you say WaitForChild("Gui"), it will never be found.

Further, since you're trying to use GUI, you should be using a LocalScript (since server scripts don't have access to the GUI). You can refer to the local player with game.Players.LocalPlayer.

Ad

Answer this question