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!
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.