Maybe add a debounce so character added doesn’t fire when you replace their character
1 Like
There may need to be some experimentation to do, maybe it only needs to run the event once just as a test since like you said, you want the characters to be changed when a player wants the change their character, so maybe do like
local changedchar = false
local function changeCharacter(player)
local search = game:GetService("ReplicatedStorage"):FindFirstChild(player.CharacterValue.Value):Clone() --Find the custom character
if search and player.Character ~= search and not changedchar then --If the custom character exists and character is not custom character
changedchar = true
search.Parent = workspace
player.Character:Destroy()
player.Character = search --Change it
workspace.CurrentCamera.CameraSubject = player.Character:FindFirstChildOfClass("Humanoid") --Changed to FindFirstChildOfClass incase your humanoid is named differently
end
end
game:GetService("Players").PlayerAdded:Connect(function(player) --When played rjoins
local CharacterValue = Instance.new("StringValue")
CharacterValue.Value = "None"
CharacterValue.Name = "CharacterValue" --Create a value in it
CharacterValue.Parent = player
player.CharacterAdded:Connect(function(char) --When the player spawns/respawns
changeCharacter(player) --change it back.
end)
end)
This is so the event only gets ran once
I’ll try to do fix this, thank you.