Gun Gui working fine on respawn in studio but not ingame

Whenever i am in studio, the gui i use works fine even when i reset, but once i get in a game and reset stuff starts breaking, after i reset in studio and pull out the gun the gui works fine but in game it errors?


I tried adding a little fix with WaitforChild but it doesnt fully work for how i want it to

local Tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Handle = Tool:WaitForChild("Handle")
local FEvent = Tool:WaitForChild("fe")
local REvent = Tool:WaitForChild("re")
local ms = player:GetMouse()
local Main = player.PlayerGui:WaitForChild("Main")
local gF = Main.GunFrame
local RunService = game:GetService("RunService")

Tool.Equipped:Connect(function()
	local Main = player.PlayerGui:WaitForChild("Main")
	local gF = Main.GunFrame
	gF.Visible = true
	gF.GunName.Text = Tool.Name
	gF.Ammo.Text = Tool.Ammo.Value
	gF.StoredAmmo.Text = Tool.StoredAmmo.Value
	gF.GunLevel.Text = "Gun Level: " .. Tool.GunLevel.Value
	gF.GunExp.Text = Tool.CurrentExp.Value .. " / " .. Tool.ReqExp.Value
end)

Tool.Unequipped:Connect(function()
	local Main = player.PlayerGui:WaitForChild("Main")
	local gF = Main.GunFrame
	gF.Visible = false
	gF.GunName.Text = "X"
	gF.Ammo.Text = "X"
	gF.StoredAmmo.Text = "X"
	gF.GunLevel.Text = "Gun Level: X"
	gF.GunExp.Text = "X / X"
end)

Tool.Ammo.Changed:Connect(function(newValue)
	if Tool.Parent:IsA("Model") then
		gF.Ammo.Text = newValue
	end		
end)

Tool.StoredAmmo.Changed:Connect(function(newValue)
	if Tool.Parent:IsA("Model") then
		gF.StoredAmmo.Text = newValue
	end		
end)

Tool.GunLevel.Changed:Connect(function(newValue)
	if Tool.Parent:IsA("Model") then
		gF.GunLevel.Text = "Gun Level: " .. newValue
	end
end)

Tool.CurrentExp.Changed:Connect(function(newValue)
	if Tool.Parent:IsA("Model") then
		gF.GunExp.Text = Tool.CurrentExp.Value .. " / " .. Tool.ReqExp.Value
	end
end)

Tool.ReqExp.Changed:Connect(function(newValue)
	if Tool.Parent:IsA("Model") then
		gF.GunExp.Text = Tool.CurrentExp.Value .. " / " .. Tool.ReqExp.Value
	end
end)

(edit, doesnt work whatsoever no matter how long you wait after respawn, i have to drop the gun and pick it up for the gui to work as intended), so should i just delay some code on the tool or is there a way i can make it work on respawn?

Bumping for a answer (char limit)

Go into the gui and scroll down and turn off “Reset on Spawn”. If you already haven’t done it already.

1 Like

:skull: thanks this worked, didnt know it would be that simple

1 Like

Don’t worry, I didn’t even know this until 3 months after I started working with guis.

1 Like