#Help with Part disappearing

1 messages · Page 1 of 1 (latest)

wraith linden
#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ActivateEvent = ReplicatedStorage:WaitForChild("ActivateEvent")

local RunService = game:GetService("RunService")
local DebrisService = game:GetService("Debris")

local TimeElapsed = 0

local LIFETIME = 5
local FIRED = false
local DEBOUNCE = false

local HumanoidRootPart
local Dropper
local CloneDrop

local Drop = Instance.new("Part")
Drop.Size = Vector3.new(1,1,1)
Drop.Anchored = true
Drop.CanCollide = false

ActivateEvent.OnServerEvent:Connect(function(Player, ACTIVATED)
    FIRED = true
    
    Dropper = ACTIVATED
    
    local Character = Player.Character or Player.CharacterAdded:Wait()
    HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
    
    CloneDrop = Drop:Clone()
    CloneDrop.Parent = game.Workspace
    CloneDrop.CFrame = CFrame.new(Dropper.CFrame.X + math.cos(math.random(90, 180) * 10), Dropper.CFrame.Y + 2, Dropper.CFrame.Z + math.sin(math.random(90, 180)) * 10)
    
    DebrisService:AddItem(CloneDrop, LIFETIME)
    
    task.wait(LIFETIME)
    FIRED = false
end)

RunService.Heartbeat:Connect(function(deltaTime)
    if FIRED then
        TimeElapsed += deltaTime
        
        CloneDrop.CFrame = CloneDrop.CFrame * CFrame.new(0, CloneDrop.Position.Y + math.sin(TimeElapsed) / 100, 0) * CFrame.Angles(0, TimeElapsed, 0)
        print(CloneDrop.CFrame)
        
        task.wait(LIFETIME - 1)
        CloneDrop.CFrame = CloneDrop.CFrame:Lerp(HumanoidRootPart.CFrame, math.pi/100)
    end
end)

The part randomly disappears after a second or so, and the CFrame seems to fluctuate, why would this happen?

wraith linden
wraith linden