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

How to change a character when a specific player / team has joined it. Without any gui and a button?

Hello! I need to make a script that allows you to change the character for a certain player or team without buttons or gui. Unfortunately, I could not find a solution to my problem on YouTube and dev forum.

repeat
	game.Players.PlayerAdded:Connect(function(plr)
		if plr.Name == "ZEWS228" then
			plr.Character = game.ReplicatedStorage.Characters.CreatorFurry
			wait(1)
		end
	end)
until
game.Players.LocalPlayer.Character.Name == "CreatorFurry"

2 comments

0

That's a pretty gnarly memory leak

0

memory leak fixes are underrated as hell (as of 8/18/21 and long before that)

2 answers

✓ Accepted answer

Problem

  • You are trying to set the player's character locally. This causes issues with how other players will see your character (I don't recommend using the client to set the character).

  • You have a memory leak occurring due to the repeat/until loop. You shouldn't connect to an event more than you need to.

Solution

  • Run the code in a server-side script to allow all players to see the new character.

  • Remove the repeat/until loop to fix a memory leak.

Code

--=== Services ===--

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--=== Variables ===--

local CreatorChar =  ReplicatedStorage:WaitForChild("Characters",10) and ReplicatedStorage.Characters:WaitForChild("CreatorFurry",10)

--=== Hooks (Connections) & Main Loop ===--

Players.PlayerAdded:Connect(function(player)
	if player.Name == "ZEWS228" then
		player.CharacterAdded:Connect(function(Character)
			if Character.Name == "CreatorFurry" then return end -- If set, don't re-set
	
			-- Set the player's character
			local oldModel = Character
			local newModel = CreatorChar:Clone()
	
			local oldCFrame = oldModel:GetPrimaryPartCFrame()
	
			player.Character = newModel
			newModel.Parent = workspace 
			newModel:SetPrimaryPartCFrame(oldCFrame)
			oldModel:Destroy()
		end)
	end
end)

Conclusion

If you have any further questions or anything in this answer was unclear, feel free to contact me via Discord (phxntxsmic#2021)

1 comment

0

Hi! Thank you for a good answer to my problem, everything works fine, but I have new problems. 1)I don't have any animations on the changed characters. 2)The character does not appear where I need it. I will be very happy if you help me :)

plr.Character:Destroy() plr.Character = game.ReplicatedStorage.Characters.CreatorFurry

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