So I have a part in the workspace and a surface gui and all of that. I originally tried a LocalScript but it didnt work, so I changed it to a server script. Everything worked until I added these things
1:
Player = game:GetService("Players").LocalPlayer
2:
Upgrade.MouseButton1Click:connect(function()
if(Player.leaderstats.Cash.Value >= Variables.UpgradeCash.Value) then
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value - Variables.UpgradeCash.Value
end
end)
The script before that was just
Upgrade = script.Parent.Upgrade
Level = script.Parent.Levels
DC = script.Parent.DC
UpgradeFrame = script.Parent.Parent.Upgrade
LevelFrame = script.Parent.Parent.Levels
UpgradeCash = script.Parent.Parent.Upgrade.CashUpgrade
Variables = script.Parent.Parent.Parent.Variables
Upgrade.MouseButton1Click:connect(function()
UpgradeFrame.Visible = true
LevelFrame.Visible = false
end)
Level.MouseButton1Click:connect(function()
UpgradeFrame.Visible = false
LevelFrame.Visible = true
end)
When I added those two things I got this error
15:49:12.326 - Workspace.Part.SurfaceGui.Frame.Script:19: attempt to index global 'Player' (a nil value)
15:49:12.330 - Stack Begin
15:49:12.332 - Script 'Workspace.Part.SurfaceGui.Frame.Script', Line 19
15:49:12.333 - Stack End
Heres my full script:
Upgrade = script.Parent.Upgrade
Level = script.Parent.Levels
DC = script.Parent.DC
UpgradeFrame = script.Parent.Parent.Upgrade
LevelFrame = script.Parent.Parent.Levels
UpgradeCash = script.Parent.Parent.Upgrade.CashUpgrade
Variables = script.Parent.Parent.Parent.Variables
Player = game:GetService("Players").LocalPlayer
Upgrade.MouseButton1Click:connect(function()
UpgradeFrame.Visible = true
LevelFrame.Visible = false
end)
Level.MouseButton1Click:connect(function()
UpgradeFrame.Visible = false
LevelFrame.Visible = true
end)
Upgrade.MouseButton1Click:connect(function()
if(Player.leaderstats.Cash.Value >= Variables.UpgradeCash.Value) then
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value - Variables.UpgradeCash.Value
end
end)

4 comments
All guis need to run on the client. So you have to use a local script. Put the local script in StarterGui and edit your variables
The above is true, but obviously you're using a SurfaceGui. Local Scripts Don't work in workspace and Regular scripts can't access Local Player.
Im sorry if you read wrong, but Im using a surface gui... On a brick...
Oops lol. That's what I meant. I'll just edit that :3