My script is supposed to check if a player has enough money to see a GUI
local player = game.Players.LocalPlayer
script.Parent.Touched:Connect(function()
if player.Data.Levels.Value == 1 then
game.StarterGui.ScreenGui.Frame.Visible = true
end
if player.Data.Levels.Value == 2 then
game.StarterGui.ScreenGui.Frame.Visible = true
end
end)
The output says
Workspace.SpawnLocation.Script:4: attempt to index nil with 'Data'
OK then yes it can’t access LocalPlayer, that’s only available for local scripts, the fix is what I gave
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player.Data.Levels.Value == 1 then
player.PlayerGui.ScreenGui.Frame.Visible = true
end
if player.Data.Levels.Value == 2 then
player.PlayerGui.ScreenGui.Frame.Visible = true
end
end
end)
Yes, sorry I just copied/pasted OPs code with that in, I will correct.
It can be done on the server side though, does not have to be local script
But either way, i’d guess that when the buttons on these frames are pressed, would want some additonal server side checks again to make sure the player really does have enough money.
You cannont access local player from a Server Script, Server Scripts are ran by Roblox Server and not your machine (Local Player) So when you get the touched event, fire a remote event, put a local script inside StarterGUI to catch this remote event and then bind your actions