[SOLVED] ViewModel's ViewportFrame not reloading after the second respawn

Here is the code:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local StarterGui = game:GetService("StarterGui")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Storage = ReplicatedStorage:WaitForChild("Storage")
local SpringModule = require(Storage:WaitForChild("SpringModule"))
local VFXModule = require(Storage:WaitForChild("VFXModule"))
local BobbleSpring = SpringModule.new()
local SwayingSpring = SpringModule.new()
local ViewModel = Storage:WaitForChild("ViewModel"):Clone() or Storage:WaitForChild("ViewModel")
local DeathEvent = Storage.DeathEvent
ViewModel.Name = Player.Name.."'s ViewModel"
ViewModel:WaitForChild("Shirt").ShirtTemplate = Character:WaitForChild("Shirt").ShirtTemplate
ViewModel.Parent = Player.PlayerGui:WaitForChild("ViewModelDisplay").ScreenGui.ViewportFrame.WorldModel

StarterGui.ViewModelDisplay:Destroy()

Player.PlayerGui:WaitForChild("ViewModelDisplay").ScreenGui.ViewportFrame.CurrentCamera = workspace.CurrentCamera

RunService.PreRender:Connect(function(deltaTimeRender)

    if ViewModel.Parent ~= Storage then
        
        ViewModel.RootPart.CanCollide = false
        ViewModel["Left Arm"].CanCollide = false
        ViewModel["Right Arm"].CanCollide = false
        VFXModule.update(ViewModel, deltaTimeRender, BobbleSpring, SwayingSpring)

    end

end)

Humanoid.Died:Connect(function()
	
	ViewModel.Parent = nil
	
end)

Player.CharacterAdded:Connect(function()
	
	Player.PlayerGui:WaitForChild("ViewModelDisplay").ScreenGui.ViewportFrame.CurrentCamera = workspace.CurrentCamera
	
	ViewModel.Parent = Player.PlayerGui:WaitForChild("ViewModelDisplay").ScreenGui.ViewportFrame.WorldModel
	
end)

the code suddenly stops working after the second respawn for some reason, and no errors show up, help is highly appreciated!

3 Likes

You are referencing the player’s character’s humanoid, but not updating it.
You can either use player.Character.Humanoid.Died, or you can update the Humanoid variable on every spawn.

odd, doing this had no change sadly.

Bump, the problem sadly still persists.

Sorry for the bump, but for anyone wondering, the problem was me not calling the :Destroy() function when the player died, then calling the .new() function when respawned.

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