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

How do I clone the local players avatar right as they join?

Asked by 4 years ago

I'm trying to make a game like one on the Wii game : Wii play and I want to make it where right as the player joins the game or when they touch a brick, it causes a clone of that player to spawn in a specific location. Thanks for any help, I'm extremely new to scripting!

0
I saw that you commented on my answer. Did you need help with anything? youtubemasterWOW 2741 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You must use the PlayerAdded event. This code will run when a player joins the game. Make sure it's a ServerScript (Regular Script) inside ServerScriptStorage.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    repeat
        wait()
    until
    player.Character -- Waits until the player's character has loaded.

    local clone = player.Character:Clone() -- Cloned Character.

    clone:MoveTo(workspace.Part.Position) -- Change workspace.Part to the part you want it to teleport to.
    clone.Parent = workspace
end)

The code below is for a brick that you touch. This uses a debounce so that the character won't spam appear. Make sure you put it inside the part you want the player to hit and make it a ServerScript (Regular Script).

local Players = game:GetService("Players") 
local debounce = false 

script.Parent.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player from it's character.

    if player and not debounce then -- Checks if the part it hit is a player.
        debounce = true
        local clone = player.Character:Clone()
        clone:MoveTo(player.Character:WaitForChild("HumanoidRootPart").Position)
        clone.Parent = workspace
        wait(2)
        debounce = false
    end
end)

Also, this is supposed to be a help website for scripts that you have already made, not a request website.

0
Make sure that you turn on Archivable for the player's character, otherwise you won't be able to clone it thatwalmartman 404 — 4y
Ad

Answer this question