Few days ago I scripted the UI for my game. Today I noticed really weird thing; when I reset or I die, the UI scripts stop working. After resetting or dying, the buttons on the right side stop working as you can see from this video:
Those UIs are handled by 2 scripts:
LocalScript 'CodesUI' (Twitter Codes UI)
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local mainUI = LocalPlayer.PlayerGui:WaitForChild("UI"):WaitForChild("MainUI")
local codesButton = mainUI:WaitForChild("MidRight"):WaitForChild("CodesFrame"):WaitForChild("CodesButton")
local codesFrame = LocalPlayer.PlayerGui:WaitForChild("UI"):WaitForChild("CodeUI"):WaitForChild("Frame")
local closeButton = codesFrame:WaitForChild("Top"):WaitForChild("ExitFrame"):WaitForChild("ExitButton")
local closeCodesUIBEvent = script.Parent.Parent.UIEvents.CodesUI.CloseCodesUI
local closeShopUIBEvent = script.Parent.Parent.UIEvents.ShopUI.CloseShopUI
local isCodesUIOpen = false
local function openCodesUI()
closeShopUIBEvent:Fire()
isCodesUIOpen = true
codesFrame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 1.5, true)
end
local function closeCodesUI()
isCodesUIOpen = false
codesFrame:TweenPosition(UDim2.new(1.5, 0, 0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 1.5, true)
end
codesButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if input.UserInputState == Enum.UserInputState.Begin then
if not isCodesUIOpen then
openCodesUI()
else
closeCodesUI()
end
end
end
end)
closeButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if input.UserInputState == Enum.UserInputState.Begin then
closeCodesUI()
end
end
end)
closeCodesUIBEvent.Event:Connect(function()
closeCodesUI()
end)
LocalScript 'ShopUI' (Shop UI)
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local mainUI = LocalPlayer.PlayerGui:WaitForChild("UI"):WaitForChild("MainUI")
local shopUI = LocalPlayer.PlayerGui:WaitForChild("UI"):WaitForChild("ShopUI")
local shopFrame = shopUI:WaitForChild("Frame")
local coinShop = shopFrame:WaitForChild("CoinScreen")
local gamepassShop = shopFrame:WaitForChild("PassesScreen")
local shopButton = mainUI:WaitForChild("MidRight"):WaitForChild("ShopFrame"):WaitForChild("ShopButton")
local closeShopButton = shopFrame:WaitForChild("Top"):WaitForChild("Frame"):WaitForChild("ExitFrame"):WaitForChild("ExitButton")
local coinShopButton = shopFrame:WaitForChild("Top"):WaitForChild("Frame"):WaitForChild("2Coins")
local gamepassShopButton = shopFrame:WaitForChild("Top"):WaitForChild("Frame"):WaitForChild("1Gamepasses")
local closeCodesUIBEvent = script.Parent.Parent.UIEvents.CodesUI.CloseCodesUI
local closeShopUIBEvent = script.Parent.Parent.UIEvents.ShopUI.CloseShopUI
local isShopUIOpen = false
local isCoinShopOpen = false
local function openShopUI()
closeCodesUIBEvent:Fire()
isShopUIOpen = true
shopFrame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 1.5, true)
end
local function closeShopUI()
isShopUIOpen = false
shopFrame:TweenPosition(UDim2.new(1.5, 0, 0.5, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 1.5, true)
end
local function openCoinShop()
isCoinShopOpen = true
gamepassShop.Visible = false
coinShop.Visible = true
end
local function openGamepassShop()
isCoinShopOpen = false
coinShop.Visible = false
gamepassShop.Visible = true
end
shopButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if input.UserInputState == Enum.UserInputState.Begin then
if not isShopUIOpen then
openShopUI()
else
closeShopUI()
end
end
end
end)
closeShopButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if input.UserInputState == Enum.UserInputState.Begin then
closeShopUI()
end
end
end)
gamepassShopButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if input.UserInputState == Enum.UserInputState.Begin then
if isCoinShopOpen then
openGamepassShop()
end
end
end
end)
coinShopButton.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
if input.UserInputState == Enum.UserInputState.Begin then
if not isCoinShopOpen then
openCoinShop()
end
end
end
end)
closeShopUIBEvent.Event:Connect(function()
closeShopUI()
end)
I have read something about âResetOnSpawnâ property of ScreenGui. However it doesnât help is it ticked or not.