Frame is not valid member of GUI although it is (bug occurs on players death)

Ok, I honestly have no clue whats the issue.

I have a GUI that located inside a folder and this folder is a child of another folder:
image
The script that I use works, it does exactly what it should: make UI visable and clone one stuff to another stuff:
image


BUT, when player dies, it errors, it says that “frame is not valid member of screengui”, so I googled, people told me that I need to use :FindFirstChild() or :WaitForChild()
(heres part of a code that errors)
image
With :FIndFirstChild() im getting error that “attempting to index nil with scrollingframe” and with :WaitForChild() - “infinite yield possible” so clearly something happens when the player dies and I don’t know what. ResetOnSpawn is already disabled

Ask for any details needed!

here’s a full script:

local Tool = script.Parent
local player = game.Players.LocalPlayer
local GUI = player:WaitForChild("PlayerGui"):WaitForChild("Folder").Stashed.ScreenGui
local StashedItemName = game.ReplicatedStorage.StashedItemName

local RandomIncomeMinutesCap = game.ReplicatedStorage.RIMC
local RIMCRemove = game.ReplicatedStorage.RIMCRemove
local RIMO = game.ReplicatedStorage.RIMO
local RIMORemove = game.ReplicatedStorage.RIMORemove

local RIDO = game.ReplicatedStorage.RIDO
local RIDORemove = game.ReplicatedStorage.RIDORemove
local RIDC = game.ReplicatedStorage.RIDC
local RIDCRemove = game.ReplicatedStorage.RIDCRemove

local cln1 = GUI.Frame.effects.RIMO:Clone()
local cln2 = GUI.Frame.effects.RIMO:Clone()
local cln3 = GUI.Frame.effects.RIMO:Clone()
local cln4 = GUI.Frame.effects.RIMO:Clone()

function onEquipped()
	RandomIncomeMinutesCap:FireServer()
	RIMO:FireServer()
	RIDO:FireServer()
	RIDC:FireServer()
	StashedItemName:FireServer("AFK")
	GUI.Enabled = true
	cln1.Parent = GUI:WaitForChild("Frame").ScrollingFrame
	cln1.Visible = true
	cln1.Name = "AFKEffect1"
	cln1.Text = "Random Income (Decadence) Chances: +15%"
	cln2.Parent = GUI:WaitForChild("Frame").ScrollingFrame
	cln2.Visible = true
	cln2.Name = "AFKEffect2"
	cln2.Text = "Random Income (Minutes) Chances: +15%"
	cln3.Parent = GUI:WaitForChild("Frame").ScrollingFrame
	cln3.Visible = true
	cln3.Name = "AFKEffect3"
	cln3.Text = "Random Income (Decadence) Cap: +5"
	cln4.Parent = GUI:WaitForChild("Frame").ScrollingFrame
	cln4.Visible = true
	cln4.Name = "AFKEffect4"
	cln4.Text = "Random Income (Minutes) Cap: +5"
	GUI:WaitForChild("poofIn"):Play()
end

function onDequipped()
	RIMCRemove:FireServer()
	RIMORemove:FireServer()
	RIDORemove:FireServer()
	RIDCRemove:FireServer()
	GUI:WaitForChild("poofOut"):Play()
	GUI.Frame.ScrollingFrame:FindFirstChild("AFKEffect1"):Remove()
	GUI.Frame.ScrollingFrame:FindFirstChild("AFKEffect2"):Remove()
	GUI.Frame.ScrollingFrame:FindFirstChild("AFKEffect3"):Remove()
	GUI.Frame.ScrollingFrame:FindFirstChild("AFKEffect4"):Remove()
	GUI.Enabled = false
	StashedItemName:FireServer("Nothing")
end

script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(onDequipped)

BASICALLY, what does it do, boost player stats, that’s why theres so many events

You may want to disable the ResetOnSpawn property of ScreenGui if it’s enabled, caused me so much problems in the past, also I tried putting screen guis in folders like this and it didn’t work for some reason so I just moved them back to be children of StarterGui. Could be a problem with how Roblox replicates it or the screen gui must be a direct child of PlayerGui to work.

1 Like

already disabled, but yeah, I probably just will put it back to startergui because I actually have no clue what’s the issue (if will work i’ll let you know)

OH MY GOD IT WORKED WHAT IN THE WORLD

context, i was trying to fix this bug for 3 days lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.