#Model doesnt get Destroyed

1 messages · Page 1 of 1 (latest)

nova flame
#

i have a script where i get a random model based on rng and it moves from waypoint1 to waypoint2 but is supposed to get destrpyed at waypoint2 but it doesnt. Here is script: local touchedConn touchedConn = model.PrimaryPart.Touched:Connect(function(hit) if hit:IsDescendantOf(Waypoint2) then touchedConn:Disconnect() model:Destroy() end end) end

#

brb

outer canopy
# nova flame i have a script where i get a random model based on rng and it moves from waypoi...

local DESTROY_DISTANCE = 5
local touchedConn

-- Physics-based collision check
touchedConn = model.PrimaryPart.Touched:Connect(function(hit)
if hit == Waypoint2 or (Waypoint2:IsA("Model") and hit:IsDescendantOf(Waypoint2)) then
touchedConn:Disconnect()
model:Destroy()
end
end)

-- Backup proximity check
local destroyCheck = game:GetService("RunService").Heartbeat:Connect(function()
if not model or not model.Parent or not model.PrimaryPart then
destroyCheck:Disconnect()
return
end

local distance = (model.PrimaryPart.Position - Waypoint2.Position).Magnitude
if distance < DESTROY_DISTANCE then
    touchedConn:Disconnect()
    destroyCheck:Disconnect()
    model:Destroy()
end

end)

#

Try ts and give me 50 robux

nova flame
#

dawg what

#

why should i give 50 rbx

outer canopy
#

I helped you

mighty beacon
mighty beacon
#

Also, if you're teleporting it directly into the other object (or just moving it in a non-physics-based way) with the .Touched, the .Touched won't trigger

nova flame
#

i still doesnt destroy?

#
local Workspace = game:GetService("Workspace")

local YoutubersData = require(ReplicatedStorage.Data.Youtubers)

local Waypoint1 = Workspace.Waypoints:WaitForChild("W1")
local Waypoint2 = Workspace.Waypoints:WaitForChild("W2")

local rng = Random.new()

local function moveToWaypoint2(model)
    if not model.PrimaryPart then
        local hrp = model:FindFirstChild("HumanoidRootPart")
        if hrp then
            model.PrimaryPart = hrp
        else
            warn(model.Name .. " has no PrimaryPart or HumanoidRootPart.")
            return
        end
    end

    local humanoid = model:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:MoveTo(Waypoint2.Position)
    end

    local touchedConn
    touchedConn = model.PrimaryPart.Touched:Connect(function(hit)
        if hit:IsDescendantOf(Waypoint2) then
            touchedConn:Disconnect()
            model:Destroy()
        end
    end)
end

local function spawnYoutuber()
    for name, info in pairs(YoutubersData) do
        if rng:NextInteger(1, 100) <= info.Chance then
            local modelTemplate = ReplicatedStorage.Youtubers:FindFirstChild(name)
            if modelTemplate and modelTemplate:IsA("Model") then
                local clone = modelTemplate:Clone()
                clone.Parent = Workspace

                clone:PivotTo(Waypoint1.CFrame)

                moveToWaypoint2(clone)
            else
                warn("Model for " .. name .. " not found in ReplicatedStorage")
            end
        end
    end
end

while true do
    spawnYoutuber()
    task.wait(5)
end
nova flame
#

dw i fixed it

#

it was the waypoint part

#

that was to small

mighty beacon
#

😔