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

how would you fix :Clone not working in custom command scripts?

Asked by 4 years ago

ok so I'm trying to have a command that when you send it, it inserts a script into everyone

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        player.Chatted:Connect(function(msg)
            if string.sub(msg, 0, 1) == "/" then
                if string.sub(msg, 2) == "command" then
                    for i, plr in pairs(game.Players:GetPlayers()) do
                        if char:FindFirstChild("TrollScript") then
                            print("already in action")
                        else
                            game.ServerStorage.TrollScript:Clone(char).Name = "TrollScript"
                            print("Added Script")
                        end
                    end
                end
            end
        end)
    end)
end)

the issue I have is that it prints that it added the script, but if I look inside my character, there's no local script that I'm inserting.

if anyone knows what's wrong, please reply the help would be appreciated.

2 answers

Log in to vote
1
Answered by 4 years ago
  1. Clone() is a blank method that returns a clone of the Instance it was called from. It doesn't have any parameters.

  2. You never gave the clone a Parent, so it just sits in thin air.

What I noticed is by you doing this...

Clone(char)

...you're telling the method to accept char as an argument to...what parameter exactly? Clone() doesn't have any parameters to fill when you call it.

0
Clone() has 1 parameter, and its the parent, unless they removed it recently gwenniekins 59 — 4y
0
No, it doesn't. Look something up before you state something randomly. DeceptiveCaster 3761 — 4y
0
I looked, and I was in a beta feature enabled world when I was making something with a lot of cloning at first, so maybe it was a beta feature? because I used it that way for ages gwenniekins 59 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

ok so I know what went wrong, it was in fact that there's not an argument for :Clone, when I originally was testing with cloning, I was on a world with beta features on, so it works now.

Answer this question