Currently working on UI for testing and learning and have stumbled across a weird problem.
My goal is to have the viewport frame just show the players avatar, and it does when you spawn in, but upon respawning it shows up as the default grey avatar. Is this just a problem for studio? Because this problem does persist within Server and Client tests.
Code for viewport frame.
local viewportFrame = script.Parent
local player = game.Players.LocalPlayer
local character:Model
if not player:HasAppearanceLoaded() then
character = player.CharacterAppearanceLoaded:Wait()
else
character = player.Character
end
character.Archivable = true
local model:Model = character:Clone()
model.Parent = viewportFrame.WorldModel
model.Parent = viewportFrame.WorldModel
local part = viewportFrame.WorldModel.Part
model:PivotTo(part.CFrame)
local viewportCam = Instance.new("Camera")
viewportCam.CFrame = CFrame.new(0, 0, 5)
viewportCam.FieldOfView = 40
viewportFrame.CurrentCamera = viewportCam
I’ve tried turning off ResetOnSpawn it, but it can lead to some buggy-ish behavior to the health bar (such as not resetting to full). I’ll probably give a go at re-scripting it and seeing if I can get anywhere.
Doesn’t seem to work, from what I’ve figured with some minor debugging, is once I respawn it counts my avatar as “loaded” despite it being pure grey, I wonder if this is a studio thing as I’ve never really seen this inside an actual game.
It seems that trying to load it with that needs to be run on a server sided script, though that wouldn’t really make sense for this as it’s local gui. Unless there’s something I’m missing?
Edit: I forgot the entire concept of having multiple scripts for one thing my bad.
Have found a solution after rewriting the script. (no idea if it’s the best way but it works)
I basically check if the players model exists in replicated storage, if it doesn’t I add it into it. I then use the model from replicated storage to show in the viewport frame.
Code for the script. (put into the viewport frame itself)
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local viewportFrame = player.PlayerGui:WaitForChild("PlayerStats").ViewportFrame
local character:Model
if player.CharacterAppearanceLoaded then
character = player.Character
else
character = player.CharacterAppearanceLoaded:Wait()
end
character.Archivable = true
local repModel:Model
if not replicatedStorage.PlayerModels:FindFirstChild(character.Name) then
print("model not found")
repModel = character:Clone()
repModel.Parent = replicatedStorage.PlayerModels
repModel.Archivable = true
else
print("model found")
repModel = replicatedStorage.PlayerModels:FindFirstChild(character.Name)
end
local viewModel:Model = repModel:Clone()
viewModel.Parent = viewportFrame.WorldModel
-- Adjust viewModel.
local part = viewportFrame.WorldModel.Part
viewModel:PivotTo(part.CFrame)
local viewportCam = Instance.new("Camera")
viewportCam.CFrame = CFrame.new(0, 0, 5)
viewportCam.FieldOfView = 40
viewportFrame.CurrentCamera = viewportCam