Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

problem with a local that indicate a local player gui , how to fix it?

i have a problem with a local here is the script

local plr = game.Players.LocalPlayer
local casa = workspace.casaAvere
local sound = script.wrong
local gui = plr.PlayerGui.hous
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if not casa.Value == true then
		if player.leaderstats.bobux.Value>50 then
			local name = script.Parent.teSTO.name
			player.leaderstats.bobux.Value = player.leaderstats.bobux.Value-50
			local textlabel = script.Parent.teSTO.SurfaceGui.TextLabel
			name.Value = player.Name
			textlabel.Text = name.Value .."'s house"
			casa.Value = true
		end
	end
	if casa.Value == true then
		gui.Enabled = true
		sound:Play()
		wait(2)
		gui.Enabled = false

	end


end)

here is the error Workspace.test.Script:4: attempt to index nil with 'PlayerGui'

1 comment

0

LocalPlayer is for LocalScript, not Script.

1 answer

i fixed the script


local casa = workspace.casaAvere

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local gui = player.PlayerGui.hous
	if not casa.Value == true then
		if player.leaderstats.bobux.Value>50 then
			local name = script.Parent.teSTO.name
			player.leaderstats.bobux.Value = player.leaderstats.bobux.Value-50
			local textlabel = script.Parent.teSTO.SurfaceGui.TextLabel
			name.Value = player.Name
			textlabel.Text = name.Value .."'s house"
			wait(2)
			casa.Value = true
		end
	end

end)


.

local casa = workspace.casaAvere
local sound = script.wrong

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local gui = player.PlayerGui.hous
	if casa.Value == true then
		gui.Enabled = true
		sound:Play()
		wait(2)
		gui.Enabled = false

	end
end)

i divided the scriptt in 2 so the gui wont appear for the first time

This discussion is preserved as it was. New answers, comments, and votes are closed.