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
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
.