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

Help me make a button that spawns a clone?

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)

9 comments

1

sorry first post so i dont know how to properly type code in

0

A clone as in a model that is not moving?

0

yeah that would be fine, i have a script to make it move

0

also sorry for the late reply, im in the process of trying to fix it lol

0

You will have to use :Clone()

0

Will the clone spawn at spawn?

0

i was looking to spawn it at a specific location not spawn

0

Try out my answer, it should spawn the clone at a specific location.

0

What is players value?

1 answer

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)

16 comments

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)

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?

0

Do remember to change local Clone = parent:Clone() to local Clone = Player.Clone()

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

0

What is the output after testing? 

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

0

how do i do that?

0

I've edited my script to what I have meant.

0

i get this error now : 04:11:20.426 - Workspace.ArenaSpawn.Script:11: '' expected near 'end'

0

Sorry, forgot to delete one "end".

0

oh its ok

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)"

0

Alright, I've fixed it for you, I'll re-edit my answer.

0

Have you checked, it should be fully functional.

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

0

No problem!

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