Help with Character Switcher

Hello Everyone! I’m making right now Puzzle game and I have question how to make Character Switcher.

  1. What do you want to achieve? I want to make character chooser. for example I have 3 raccoons and I want to make so player can switch raccoons, and if player choosed Raccoon 2 when he is on Raccoon 1, then it’s saving position of Raccoon 1.

  2. What is the issue? I’ve already made first version of it, but I have a lot of bugs, for example in LocalScript I have raccoonPlaying local, and I have checker that checks if player already playing on this Raccoon, but it’s not changing at all. And I have second bug that it’s not saving raccoons position in table.

  3. What solutions have you tried so far? I didn’t find any solutions and no one asking about it, or maybe asking but I didn’t find.

Server Script:

local rs = game:GetService("ReplicatedStorage")
local remote = rs.Remotes.Events.Chooser

remote.OnServerEvent:Connect(function(plr,char,cf)
	local newChar = rs.Characters[char]:Clone()
	if game.StarterPlayer:FindFirstChild("StarterCharacter") then
		game.StarterPlayer.StarterCharacter:Destroy()
	end
	newChar.HumanoidRootPart.Anchored = false
	newChar.Name = "StarterCharacter"
	newChar.Parent = game.StarterPlayer
	plr:LoadCharacter()
	
	newChar.PrimaryPart.CFrame = cf
end)

Local Script:

local raccoonPos = {
	["1"] = CFrame.new(13.348, 2.35, -13.243),
	["2"] = CFrame.new(-29.027, 2.35, -1.142)
}
local raccoonPlaying = 1

local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local rs = game:GetService("ReplicatedStorage")
local characters, remote = rs.Characters, rs.Remotes.Events.Chooser

local btns = script.Parent
btns["1"].Activated:Connect(function()
	if raccoonPlaying == 1 then
		warn("Already choosed!")
	else
		raccoonPlaying = 1
		raccoonPos["2"] = char.PrimaryPart.CFrame
		remote:FireServer("Raccoon1", raccoonPos["1"])
	end
end)
btns["2"].Activated:Connect(function()
	if raccoonPlaying == 2 then
		warn("Already choosed!")
	else
		raccoonPlaying = 2
		raccoonPos["1"] = char.PrimaryPart.CFrame
		remote:FireServer("Raccoon2", raccoonPos["2"])
	end
end)

I don’t have any errors in output, so if someone can help, that would be really appreciated! Thanks.

6 Likes

Maybe because you started with 1 and not 0? So if thats the case then the code reads like its never gonna fire the remote

What do you mean about that? Read the script properly. It’s just a local

Oh my bad. So actually in this case you will have to put the warn in the else setting it to 1 and the the other part of the script to detect the player and change his position

Remove this and set plr.Character to newChar

I don’t see any plr.Character

charrs

Character is a property of plr

Umm, it’s didn’t fixed any bugs that I have. But, now it’s not changing the characters.

Remove plr:LoadCharacter() and parent newChar to workspace

It’s even got worse, my camera stopped working

Idk, if you did everything I said it should be right, can you show me your updated code?

Sure.

local rs = game:GetService("ReplicatedStorage")
local remote = rs.Remotes.Events.Chooser

remote.OnServerEvent:Connect(function(plr,char,cf)
	local newChar = rs.Characters[char]:Clone()
	newChar.HumanoidRootPart.Anchored = false
	newChar.Name = "StarterCharacter"
	newChar.Parent = game.StarterPlayer
	
	plr.Character = newChar
	newChar.PrimaryPart.CFrame = cf
	
	warn("Choosed")
end)

Set the parent after you have set the player’s character.

Okay, thanks, it’s changing character but It’s not changing the raccoonPlaying

Hmm… I have a theory on what might be going on. Where is this local script located?

In the GUI where the buttons located
image

What is happening is that when you are morphing into a new character, you are being respawned and so the ScreenGui and its descendants are resetting.

Just turn off ResetOnSpawn on the ScreenGui and you should be good :slight_smile:

Thanks it’s working now! I need only to make saving position.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.