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
#Model doesnt get Destroyed
1 messages · Page 1 of 1 (latest)
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
if hit:IsDescendantOf(Waypoint2) then
touchedConn:Disconnect()
model:Destroy()
end
it's most likely just not detecting hit as a descendant of waypoint2, and therefore not continuing with the model:Destroy() or the disconnect
Thats enough
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
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
😔