Ad
Log in to vote
1

Help me make a button that spawns a clone?

Asked by 4 days ago
Edited 4 days ago

I have a partial script that reacts when you touch it but i want it to spawn a clone of the player that touches it at a specific location. Any help would be appreciated :P

Here is the script:

local button = game.Workspace.ArenaSpawn

local function createclone(other)
    local parent = other.Parent
    if game.Players:GetPlayerFromCharacter(parent)then

    end
end

button.Touched:connect(createclone)

Script after doing what i think you told me lol :

local button = game.Workspace.ArenaSpawn

local function createclone(player)
    local parent = player.Parent
    --Clone player
    local Clone = parent:Clone()
    Clone.Parent = game.workspace
    Clone:MoveTo(button.Position)

    end

button.Touched:connect(createclone)

1
sorry first post so i dont know how to properly type code in sora10056 1 — 4d
0
A clone as in a model that is not moving? AbandonedRick 45 — 4d
0
yeah that would be fine, i have a script to make it move sora10056 1 — 4d
0
also sorry for the late reply, im in the process of trying to fix it lol sora10056 1 — 4d
View all comments (5 more)
0
You will have to use :Clone() AbandonedRick 45 — 4d
0
Will the clone spawn at spawn? AbandonedRick 45 — 4d
0
i was looking to spawn it at a specific location not spawn sora10056 1 — 4d
0
Try out my answer, it should spawn the clone at a specific location. AbandonedRick 45 — 4d
0
What is players value? wookey12 40 — 3d

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
1
Answered by 4 days ago
Edited 4 days ago

Here's your current script:

local button = game.Workspace.ArenaSpawn

local function createclone(other)
    local parent = other.Parent
    if game.Players:GetPlayerFromCharacter(parent)then

    end
end

button.Touched:connect(createclone)

So you would like a script that would create a clone of the player that touches it. Continuing on on your script, you have already started the part on the button being touched. With that part out of the way, here is how you would clone.

In your script, other, is the hit, which would be the body part of the player. Thus, parent, would be the player. I do suggest you change its name to "Player" to avoid confusion. Anyway, in order to clone, you should use Clone() which will be used to clone the player. After cloning, place the clone into workspace. And finally, to move a model, in this case, a clone, you should use MoveTo() to move the clone to your desired location, in this case, the button.

Here's the new edit, find for the one you'd like:

1 This is for one time use every time touched

local button = game.Workspace.ArenaSpawn
local Done = false

local function createclone(other)
    humanoid = other.Parent:FindFirstChild("Humanoid")
    if humanoid and not Done then
    local player = other.Parent
    player.Archivable = true
    --Clone player
    local Clones = player:Clone()
    Clones.Parent = game.Workspace
    Clones:MoveTo(button.Position)
    player.Archivable = false
    Done = true
    end
end

button.Touched:connect(createclone)

2 This is for many time use with a cool down of one second

local button = game.Workspace.ArenaSpawn
local Done = false

local function createclone(other)
    humanoid = other.Parent:FindFirstChild("Humanoid")
    if humanoid and not Done then
    Done = true
    wait(1)
    local player = other.Parent
    player.Archivable = true
    --Clone player
    local Clones = player:Clone()
    Clones.Parent = game.Workspace
    Clones:MoveTo(button.Position)
    player.Archivable = false
    Done = false
    end
end

button.Touched:connect(createclone)
0
when i tried it i got this error : 03:50:46.258 - Workspace.ArenaSpawn.Script:7: attempt to index local 'Clone' (a nil value) sora10056 1 — 4d
0
Hmmm... I don't seem to be able to spot any errors, could you try replacing the name of the variable other.Parent to local Player = other.Parent? AbandonedRick 45 — 4d
0
Do remember to change local Clone = parent:Clone() to local Clone = Player.Clone() AbandonedRick 45 — 4d
0
ok i'll just post the script i have now after doing the corrections that you talked about, like changing the "other" to "player" and stuff sora10056 1 — 4d
View all comments (12 more)
0
What is the output after testing?  AbandonedRick 45 — 4d
0
04:05:21.852 - Place1 was auto-saved 04:05:25.053 - Workspace cannot be cloned 04:05:25.055 - Stack Begin 04:05:25.057 - Script 'Workspace.ArenaSpawn.Script', Line 6 04:05:25.058 - Stack End 04:05:34.928 - Workspace.ArenaSpawn.Script:7: attempt to index local 'Clone' (a nil value) 04:05:34.930 - Stack Begin 04:05:34.931 - Script 'Workspace.ArenaSpawn.Script', Line 7 04:05:34.933 - Stack End sora10056 1 — 4d
0
how do i do that? sora10056 1 — 4d
0
I've edited my script to what I have meant. AbandonedRick 45 — 4d
0
i get this error now : 04:11:20.426 - Workspace.ArenaSpawn.Script:11: '<eof>' expected near 'end' sora10056 1 — 4d
0
Sorry, forgot to delete one "end". AbandonedRick 45 — 4d
0
oh its ok sora10056 1 — 4d
0
it's still giving me the same error. when i spawn the output it says "workspace cannot be cloned" and ten when i step on it it says "Workspace.ArenaSpawn.Script:7: attempt to index local 'Clone' (a nil value)" sora10056 1 — 4d
0
Alright, I've fixed it for you, I'll re-edit my answer. AbandonedRick 45 — 4d
0
Have you checked, it should be fully functional. AbandonedRick 45 — 4d
0
Omg thanks man, you're a saint. i've been working on this for hours. this was a really big help, the game i'm trying to make revolves around cloning so i really needed this. i'll definitely be looking over this script to see how it functions so i can maybe learn from it :P sora10056 1 — 4d
0
No problem! AbandonedRick 45 — 4d
Ad

Answer this question



Ad