So basically, I made a GUI where after clicking on a button, A rig (with a humanoid and animation scripts) is cloned from replicatedstorage to workspace and assigned as your character. (I used player.Character) Other than the fact that I had to add additional script for the camera being linked to the new character’s head, it was all was working smoothly…that is until I realized that the normal health bar doesn’t change when you’re damaged or healed.
Just for extra specification, by health bar, I’m talking about the default roblox one that’s by your name at the top right. I haven’t made my own GUI.
I investigated a bit and tried getting damaged with my own character (roblox avatar) instead of the custom one. The health bar was responding accordingly and it lowered as I took more damage, so this leads me to believe it’s something with either the switch between characters or the custom character itself is the cause for this. If anyone who’s dealt with stuff like this before could give a solution (entire scripts are not needed), that would be great!
If any more information is needed, feel free to ask!
when the default player spawns in (before character change) you use player.Character so it gets their old character which contains the healthbar. When you change the character the script is still referencing the old character which i assume gets destroyed. Try referencing the players character after their custom character as been spawned
Alright.
Some extra stuff is that this code is under an ImageButton. There is also a RemoteEvent object under the same imagebutton. The localscript recieves the click and fires the remote event and controls the camera of the player, but the server script does everything else.
Localscript:
function mouseclick()
local player = game.Players.LocalPlayer
script.Parent.RemoteEvent:FireServer()
script.Parent.Parent.Parent.Enabled = false
local camera = game.Workspace.CurrentCamera
local rig = game.Workspace:WaitForChild(player.Name.."2")
camera.CameraType = "Custom"
camera.CameraSubject = rig:WaitForChild("Head")
end
script.Parent.MouseButton1Click:Connect(mouseclick)
Serverscript:
local remoteEvent = script.Parent.RemoteEvent
local function suitchange(player)
local actualplayer = game.Players:WaitForChild(player.Name)
local clone = game.ReplicatedStorage.SpiderMan:Clone()
clone.Name = player.Name.."2"
clone.Parent = game.Workspace
actualplayer.Character = clone
player.PlayerGui:FindFirstChild("Character Selection").Enabled = false
local yes = game.StarterPlayer.StarterCharacterScripts.WallClimb:Clone()
yes.Parent = clone
local webshooter = game.ReplicatedStorage["Web Shooter"]:Clone()
webshooter.Parent = actualplayer.Backpack
local webs = game.ReplicatedStorage["Spider-Webs"]:Clone()
webs.Parent = actualplayer.Backpack
end
remoteEvent.OnServerEvent:Connect(suitchange)
The original character completely gets removed from the game after the character is switched. However, one thing to note might be that the script I have names the new rig the player’s username, but it adds a “2” to the end of the username. The actual name of the player in game.Players remains the same.
For example, if your roblox username was “bot”, the playercharacter would be called “bot2”, but your player would still obviously be called “bot”.
Alright. It’s getting very late where I live so I’ll try again tomorrow. I’m going to probably attempt seeing if moving the humanoid from the old character to the new one is possible and if it’ll fix it. Thanks for your help!