Remote Event to switch a character's model?

I’m working on a customization system, essentially it starts by asking if you are a boy or a girl to move onto the armor/weapon choices.

I have the script working, it takes the corresponding models from replicated storage and replaces the player’s character, however, acts as though I’m respawning or loading the character and resetting the UI instantly.

I’ve tried many methods, even something as simple as putting both models in StarterPlayer and just renaming them before taking the health to 0 to “StarterCharacter” depending on if you chose boy or girl.

Here is the code within my UI that applies when activating the buttons.

boyButton.Activated:Connect(function()
	local player = game.Players.LocalPlayer
	if player then
		selectSound:Play()

		LoadCharacterEvent:FireServer("Boy")

		boyorgirlFrame.Visible = false
		boycharacterFrame.Visible = true
		
		spawnSound:Play()
		music.Volume = 0
		
		mainCamera.CameraType = Enum.CameraType.Follow
	end
end)


girlButton.Activated:Connect(function()
	local player = game.Players.LocalPlayer
	if player then
		selectSound:Play()

		LoadCharacterEvent:FireServer("Girl")

		boyorgirlFrame.Visible = false
		girlcharacterFrame.Visible = true
		
		spawnSound:Play()
		music.Volume = 0
		
		mainCamera.CameraType = Enum.CameraType.Follow
	end
end)

Here is the remote event code.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LoadCharacterEvent = ReplicatedStorage.Events:WaitForChild("LoadCharacterEvent")
local mainCamera = game.Workspace.Camera
local playerStartSpawn = game.Workspace.Spawns:WaitForChild("PlayerStart")

LoadCharacterEvent.OnServerEvent:Connect(function(player, characterType)
	if player.Character then
		player.Character:Destroy()
	end

	if characterType == "Boy" then
		player.Character = game.ServerStorage:WaitForChild("StarterBoyCharacter"):Clone()
	end
	if characterType == "Girl" then
		player.Character = game.ServerStorage:WaitForChild("StarterGirlCharacter"):Clone()
	end

	player.Character.Parent = workspace
	mainCamera.CameraType = Enum.CameraType.Follow

	local newCFrame = playerStartSpawn.CFrame:ToWorldSpace(CFrame.new(0, 2, 0))
	player.Character:SetPrimaryPartCFrame(newCFrame)
end)

Towards the end it just places the character at one of the spawn points and makes the camera follow them since I have it initially set to be an overhead view of the map.

2 Likes

Disable the ResetOnSpawn property in the starterGui

That works! At least for the initial spawn. After the player dies it does need to come back, however, I’m just not sure why it acts as though it’s respawning the character here. Thanks for the help!

1 Like

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