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

NO script EVER will get PlayerGui from LocalPlayer, why wont it get PlayerGui?

local Detector = script.Parent.ClickDetector
local Tool = game.Workspace["Green Key"]
local Part = script.Parent

Detector.MouseClick:Connect(function(Player)
	game.Workspace.BoogieBattle.boogiedispenser.sign.Part.SurfaceGui.TextLabel.Visible = true
	if game.Players.LocalPlayer.PlayerGui.Values.NC.NCValue.Value == 10 then
		local Clone = Tool:Clone()
		local handle = Clone:FindForChild("Handle")
	Clone.CFrame = game.Workspace.tppart.CFrame
		Part:Destroy()
	else
		game.Workspace.BoogieBattle.boogiedispenser.sign.Part.SurfaceGui.TextLabel.Text = "You dont have enough NoseCoins!"
		wait(3)
		game.Workspace.BoogieBattle.boogiedispenser.sign.Part.SurfaceGui.TextLabel.Text = "You must pay 10 Nose Coins to play Boogie Battle"
	end
end)

This script above is a script that needs to find PlayerGui, so it can either post a message and dispense a key, or show a different message.

I have many scripts with this error, and this error: "Attempt to index nil as "PlayerGui" keeps destroying my sanity to get my games finished.

2 comments

0

Use :WaitForChild("PlayerGui") when you refer to playergui

0

just appears with attempt to index nil with wait for child

1 answer

✓ Accepted answer

Try doing:

local Detector = script.Parent.ClickDetector
local Tool = workspace:FindFirstChild("Green Key")
local Part = script.Parent

Detector.MouseClick:Connect(function(Player)
    game.Workspace.BoogieBattle.boogiedispenser.sign.Part.SurfaceGui.TextLabel.Visible = true
    if Player.PlayerGui.Values.NC.NCValue.Value == 10 then
        local Clone = Tool:Clone()
        local handle = Clone:FindForChild("Handle")
    Clone.CFrame = workspace.tppart.CFrame
        Part:Destroy()
    else
        workspace.BoogieBattle.boogiedispenser.sign.Part.SurfaceGui.TextLabel.Text = "You dont have enough NoseCoins!"
        wait(3)
        workspace.BoogieBattle.boogiedispenser.sign.Part.SurfaceGui.TextLabel.Text = "You must pay 10 Nose Coins to play Boogie Battle"
    end
end)

I see you are using value objects and I would highly not use those because they are really easy for exploiters to abuse. I think this should solve your issues

3 comments

0

Value objects are not easy to exploit if there are sanity checks and are used only on server-side.

0

In line 9, you're totally wrong. It must be 'FindFirstChild' NOT 'FindForChild'

0

cool thanks 7zjh and Gabe_elvin1226aclan

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