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

Script won't work after player resets or until the script is disabled and enabled again?(FE)

Inside of StarterPlayerScripts, there is a local script that opens a gui when another gui is pressed. It works but only until the player resets. The game is filteringenabled and I am using a Test Server instead of test mode. Any idea what is wrong here?

local Player = game.Players.LocalPlayer
local Open = Player:WaitForChild("PlayerGui"):WaitForChild("SkillGui").SkillB
local Skills = Open.Parent.Skills


--[[Open.MouseButton1Click:connect(function()
    print("Clicked")
    local scriptthing=Open
scriptthing.Parent.Skills.Visible=true
    print("Ran")
end)]]

local function OnClicked()
	print("clicked")
	if Skills.Visible == false then
		Skills.Visible = true
	elseif
		Skills.Visible == true then
		Skills.Visible = false
	end
end

Open.MouseButton1Click:connect(OnClicked)


1 answer

✓ Accepted answer

This is due to the fact that PlayerGuis are filled from StarterGui upon respawn.

You reference the guis: Open and Skills, which then become nil when the player respawns.

An easy fix to this would be to place a LocalScript directly inside the GuiButton object, so that the reference to said button will always be a constant script.Parent.

######note: you can use the logical not operator to indicate negation

local Player = game.Players.LocalPlayer
local Open = script.Parent --Placed inside the button
local Skills = Open.Parent.Skills

Open.MouseButton1Down:Connect(function()
	Skills.Visible = not Skills.Visible --'not' operator usage.
end)

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