local Remote = script:WaitForChild("Event")
game.Players.PlayerAdded:Connect(function(player)
local GamePassIdObject = script:WaitForChild('GamePassId')
player.CharacterAdded:Connect(function(char)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) or char.Name == "Player1" --[[or char.Name == "PlayerName" Example: or char.Name == "Evenous"]] then
require(game:GetService("ReplicatedStorage"):WaitForChild("DRadio_Giver"))(player)
local Gui = script.DRadio:Clone()
Gui.Parent = player.PlayerGui.Main.Frame
end
end)
the script doesn’t end here, there are other parts to the script that has to be kept, which means I cannot destroy the script. Is there a way to disable just this part of the script after it executes once? It keeps on duplicating the Frame every time a humanoid dies. (Sorry for the unorganized post, I really needed a quick reply.)
Is The ScreenGUI has Disabled ResetOnSpawn?
If Yes Then The ScreenGUI Will Not Be Reseted On Respawn And It Will Make More Frame Clones On When The Humanoid Dies.
You are adding GUI every time playe respawns because it is inside the function that is connected to Player.CharacterAdded event.
You can change it a bit like this so it doesn’t clone the frame like that:
local Remote = script:WaitForChild("Event")
game.Players.PlayerAdded:Connect(function(player)
local GamePassIdObject = script:WaitForChild('GamePassId')
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) or player.Name == "Player1" --[[or player.Name == "PlayerName" Example: or player.Name == "Evenous"]] then
local Gui = script.DRadio:Clone()
Gui.Parent = player:WaitForChild("PlayerGui"):WaitForChild("Main"):WaitForChild("Frame")
player.CharacterAdded:Connect(function(char)
require(game:GetService("ReplicatedStorage"):WaitForChild("DRadio_Giver"))(player)
end)
end
end)
When I close the first bracket, the ‘char’ part gets highlighted in orange, causing a weird bug where it says Main is not a child of Player.PlayerGui, when it clearly is.
Change char with player in the if statement and player.PlayerGui.Main.Frame with player:WaitForChild("PlayerGui"):WaitForChild("Main"):WaitForChild("Frame") on the line 6 so code waits for required GUI objects to load.