Hey, I have some module scripts Designed for Guis in StarterPlayerScripts.Handlers required by a local script in StarterPlayerScripts. The Problem is that after every character reset the module breaks with no error message. For example the Sound module for hovering and clicking UI buttons playes both sounds when resetting and after that is breaks with no error message, same for the other ones
#Modules breaking after Player reset
1 messages · Page 1 of 1 (latest)
Cool.
the ResetOnSpawn propery of ScreenGui is on by default
which means the ui gets deleted and replaced by startergui when you die
you can either disable it or make your modules run the ui code every respawn
The weird thing is that this doesnt affect the script
How can i make this
Yeah i already turned it off, it doesnt care if its on or not
local SelectFrameHover = game.Players.LocalPlayer.PlayerGui.MainMenu.ScreenGui.Frame.ButtonHolder
local SelectButton = SelectFrameHover.PlayButton
local CollectionService = game:GetService("CollectionService")
--Sound IDs
local SoundID = 126396615394424
local ClickSoundID = 4499400560
local module = {}
SelectButton.MouseEnter:Connect(function()
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://"..SoundID
sound.Volume = 0.5
sound.Parent = script
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end)
SelectButton.MouseButton1Click:Connect(function()
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://"..ClickSoundID
sound.Volume = 0.8
sound.Parent = script
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end)
local HoverSoundComponentsTable = CollectionService:GetTagged("HoverSound")
local function connectHover(uiElement)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://"..SoundID
sound.Volume = 0.5
sound.Parent = script
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end
Part 1
for _, uiElement in ipairs(HoverSoundComponentsTable) do
uiElement.MouseEnter:Connect(function()
connectHover(uiElement)
end)
end
CollectionService:GetInstanceAddedSignal("HoverSound"):Connect(connectHover)
local ClickSoundComponentsTable = CollectionService:GetTagged("ClickSound")
local function connectClick(uiElement)
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://"..ClickSoundID
sound.Volume = 0.5
sound.Parent = script
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end
for _, uiElement in ipairs(ClickSoundComponentsTable) do
uiElement.MouseButton1Click:Connect(function()
connectClick(uiElement)
end)
end
CollectionService:GetInstanceAddedSignal("ClickSound"):Connect(connectClick)
return module
Part 2
Maybe its the script?