Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To Stop It From Making 2 Folders?

Ive Been Working On A Simulator And I Have A Script That Keeps Duplicating And IVe Tried So Many Things But Nothing Has Worked

Code:

local serverstorage = game:GetService("ServerStorage")
local Debounce = false
game.Players.PlayerAdded:Connect(function(player)
	
	
	if Debounce == false then
		Debounce = true
		local datafolder = Instance.new("Folder")
		datafolder.Name = player.Name
		datafolder.Parent = serverstorage.RemoteData
		print("Created")

		local Debounce = Instance.new("BoolValue")
		Debounce.Name = "Debounce"
		Debounce.Parent = datafolder
		Debounce = false
	end
end)

Thanks For Helping

1 comment

0

Is it not common sense to wait before you set the debounce variable back? I think this is just misusing a debounce.

1 answer

✓ Accepted answer

On line 2, you assign Debounce to a boolean. Meaning that it is either true, false, or nil.

On line 13 however, you assign Debounce to a instance.

And then on line 16 you attempt to assign a boolean to an instance which is IMPOSSIBLE.

You want to access the Value property of Debouce, like so

Debounce.Value = false;

Final code, edited:

local serverstorage = game:GetService("ServerStorage")
local Debounce = false
game.Players.PlayerAdded:Connect(function(player)
    if Debounce == false then
        Debounce = true
        local datafolder = Instance.new("Folder")
        datafolder.Name = player.Name
        datafolder.Parent = serverstorage.RemoteData
        print("Created")
        -- i'd like to heavily stress that below is not required
        local Debounce = Instance.new("BoolValue")
        Debounce.Name = "Debounce"
        Debounce.Parent = datafolder
        Debounce.Value = false
    end
end)

Also, you do not need to capitalise the first letter of each word!

This discussion is preserved as it was. New answers, comments, and votes are closed.