Broken backpack Gui buttons

Sorry in advanced, still new to all this

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to find solutions on how to fix GUI buttons.

  2. What is the issue? Include screenshots / videos if possible!
    Every time the player dies all buttons inside the scrolling frame breaks
    (This is with ResetOnSpawn disabled)

robloxapp-20201226-1422089.wmv (2.4 MB)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    So when ResetOnSpawn was disable I tried adding a while true loop(spawn function) to add all children in my scrolling frame and added to my button connections.

That didn’t work either I turned on ResetOnSpawn and tried to spawn new instances of templates into the scrolling frame with the while true loop mentioned above.

I’ve tried doing research on my problem, but cannot find a solution to my problem yet.
Also I might be executing incorrectly since this is my first time making a GUI, (I followed alvinblox’s tutorial)

I would also like feedback and tips on scripting if possible

Heres my script so far.


local studio = game.Workspace.Studio 

local temp = script:WaitForChild("Temp")
local ScrollingFrame = script.Parent:WaitForChild("ScreenGui"):WaitForChild("BackpackF"):WaitForChild("packFrame"):WaitForChild("ScrollingFrame")

local buttonConnections = {}

local function setTempEquip(temp)
	for i, v in pairs(ScrollingFrame:GetChildren()) do
		if v:FindFirstChild("Equipped") then
			v.Equipped.Text = "UNEQUIPPED"
			v.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
		end
	end
	temp.Equipped.Text = "EQUIPPED"
	temp.Equipped.TextColor3 = Color3.fromRGB(0,255,0)
	
end

    function addToFrame(sword)

	local newTemp = temp:Clone()
	newTemp.Name = sword.Name
	newTemp.SwordName.Text = sword.Name
	newTemp.Parent = ScrollingFrame
	
	local newSword = sword:Clone()
	newSword.Parent = newTemp.ViewportFrame
	
	local camara = Instance.new("Camera")
	camara.CFrame = CFrame.new(newSword:FindFirstChild("Handle").Position + (newSword:FindFirstChild("Handle").CFrame.upVector * 5), newSword:FindFirstChild("Handle").Position)
	camara.Parent = newTemp.ViewportFrame
	
	newTemp.ViewportFrame.CurrentCamera = camara
	
	buttonConnections[#buttonConnections+1] = newTemp.MouseButton1Click:connect(function()
		if newTemp.Equipped.Text == "EQUIPPED" then
			game.ReplicatedStorage.UnequipSword:FireServer()
			newTemp.Equipped.Text = "UNEQUIPPED"
			newTemp.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
		else
			game.ReplicatedStorage.EquipSword:FireServer(sword.Name)
			setTempEquip(newTemp)
		end
	end)
end

game.ReplicatedStorage.SendData.OnClientEvent:Connect(function(swordName)
	for i , swordName in pairs(swordName) do
		if game.ReplicatedStorage.SWORDBANK:FindFirstChild(swordName) then
			addToFrame(game.ReplicatedStorage.SWORDBANK:FindFirstChild(swordName))
		end
	end
end)


game.ReplicatedStorage.OpenCrate.OnClientEvent:Connect(function(sword)
addToFrame(sword)
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 10
	explosion.BlastPressure = 0
	explosion.Position = studio.crate.Position
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.DestroyJointRadiusPercent = 0
	explosion.Parent = studio.crate
	
	studio.crate.Transparency = 1
	local swordC = sword:clone()

	for i,v in pairs(swordC:GetChildren()) do
		if v:IsA("Part") then
			v.Anchored = true
			v.Position = studio.crate.Position
		end
	end
	swordC.Parent = studio
	wait(3)
	studio.crate.Transparency = 0
	swordC:Destroy()
end)
---------------------------


Hello pie9909,

Do you have any errors in the output? This can be opened by going to the view section and enabling Output.

Regards
FretfulKian154

Hello,

no, there are no errors in the output while running the script, not even warnings

Where did you put the Script? And why are you doing script.Parent:WaitForChild("ScreenGui")?

The script is in StarterGui, i used WaitForChild(“ScreenGui”) to find the GUI when it loads, idk should I move this script elsewhere? maybe into the screen Gui?
image

Sorry for the late response, yes try moving the Script into the ScreenGui and change the variable to script.Parent instead

No worries, I’m just glad that somebody is helping me lol

also thank you very much, the buttons work fine!