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!