Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To Stop It From Making 2 Folders?

Asked by 3 years ago

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

0
Is it not common sense to wait before you set the debounce variable back? I think this is just misusing a debounce. DeceptiveCaster 3761 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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!

Ad

Answer this question