What do you want to achieve? Keep it simple and clear!
If you click a button, I want the Health, Stamina bar etc. to appear when spawned without it disappearing after 0.5 seconds.
What is the issue?
The stat bars appear for 0.5 seconds and then randomly disappear. GUI Issue
What solutions have you tried so far?
I asked in a Discord Server and watched YouTube tutorials but I didn’t find anything related to my issue.
local Folder = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("BengalTiger")
local HealthBar = Folder.Health
local StaminaBar = Folder.Stamina
script.Parent.MouseButton1Click:Connect(function()
HealthBar.Enabled = true
StaminaBar.Enabled = true
end)
The thing is, that it should be a character selection and that’s why they’re in a folder because if you click on tiger for instance you will get the healthbar and the hp which are made for the tiger and if you select another animal so on…
And ty because of the offset sizing, I’ll see what I can do. Atm I want it to work on PC only
Fixed!
Just replace the “ChangeCharacter” script in ServerScriptService with this script:
local changeEvent = game.ReplicatedStorage:WaitForChild("ChangePlayerCharacter")
local charsFolder = game.ReplicatedStorage:WaitForChild("Characters")
changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
if charsFolder:FindFirstChild(chosenCharacter) then
local newChar = charsFolder:FindFirstChild(chosenCharacter):Clone()
local plrChar = player.Character
if newChar:FindFirstChild("HumanoidRootPart") then
newChar.PrimaryPart = newChar.HumanoidRootPart
newChar:SetPrimaryPartCFrame(plrChar.HumanoidRootPart.CFrame)
elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
newChar.PrimaryPart = newChar.Torso
newChar:SetPrimaryPartCFrame(plrChar.Torso.CFrame)
end
if player.Character:FindFirstChild("Animate") then
local anim = player.Character:FindFirstChild("Animate"):Clone()
anim.Parent = newChar
end
newChar.Name = player.Name
player.Character = newChar
local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character:FindFirstChild("Torso")
if rootPart and plrRoot then
rootPart.CFrame = plrRoot.CFrame
end
newChar.Parent = workspace
local Folder = player:WaitForChild("PlayerGui"):WaitForChild("BengalTiger")
local HealthBar = Folder.Health
local StaminaBar = Folder.Stamina
HealthBar.Enabled = true
StaminaBar.Enabled = true
else
warn("character doesnt exist or something went wrong.")
end
end)
I know you have solved this, but your game revolves around swapping character models, so I thought I’d share what I know.
I suspect the health bar disappears because you changed character models, and the Humanoid killed you, resetting your gui. This isn’t a 0.5 second delay, this is a frame or two. Note that you “fall” like you have been respawned.
In order to swap out character models without this instant kill, you need to enter a model without a Humanoid, then add the Humanoid after the swap.