my player is defind here since i couldnt figure out how to find local player in a normal script
1 | game.Players.PlayerAdded:Connect( function (player) |
1 | local price = player.PlayerGui:WaitForChild( "Gui" ).Main.Info.Price |
2 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
3 | local Cash = leaderstats:FindFirstChild( "Cash" ) |
4 |
5 | if Cash.Value > = price.Value then |
6 | Cash.Value = Cash.Value - price.Value |
The "price" is a intValue. When I did
1 | local price = 100 |
it worked. But when i changed it back to
1 | 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
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
.