Would like some quick help on troubleshooting a script!

Hello, all!

I’ve caught myself in a really weird situation.

My game has a rainy environment which we’re introducing as part of a fun event, temporarily.

The rain script duplicates its assets into the player’s PlayerGui - I found this by testing in studio and in-game using Adonis’ Dex function.

I wrote a localscript due to feedback regarding loss of performance due to the rain.

It’s contained within a text button, as part of the LocalPlayer’s PlayerGui.

The script literally ceases to function, but I have no errors. None in my code, none in my local output, none anywhere.
It just doesn’t work.

Am I doing something wrong?

For reference:
Take script.Parent to be a TextButton.
Take Items to contain names of things stored in the LocalPlayer’s PlayerGui.
Take StarterGui as a place that contains all the elements I can recover for the user.

Code:

local Items = {"Rain", "RainyDay", "SoundPlayer", "SplashRenderer", "Splash", "DropSurface", "DropleSurface", "Raindrop"}
local Player = game:GetService("Players").LocalPlayer
local PGui = Player:WaitForChild("PlayerGui")

script.Parent.MouseButton1Click:Connect(function()
	for i,a in pairs(PGui:GetChildren()) do
		if Items[a.Name] then
			a:Destroy()
		else
			for i,v in pairs(game.StarterGui:GetChildren()) do
				if Items[v.Name] then
					v:Clone().Parent = PGui
				end
			end
		end
	end
end)

Any help or suggestions are appreciated. Thank you!

1 Like

Don’t Destroy the UI. Use ScreenGui.Enabled instead

Problem with your method is that by destroying the uis, the scripts also get deleted. If you try cloning a script, as a client, into a place where it’ll execute, it won’t get replicated to the server and the client will never actually receive the actual instructions.

my roblox networking knowledge aren’t accurate btw so dont quote me on that

Edit: I overlooked a small issue:
Items[a.Name] will always return nil, because your table doesn’t have values with any of those indexes. Items[1] is “Rain”, Items[2] is “RainyDay” et cetera.

I recommend you use
if table.find(Items, a.Name) then instead.