So I made a tool that whenever you click on It, a train from replicastorage will carry the player, destroying parts when It touches the train, however I found a problem, the train works normally, as well of the script but It appears that the train doesn't destroy the parts, however for some reason making the player noclip Into them
Script:
local tool = script.Parent local Debounce = false local WaitTime = 30 tool.Activated:Connect(function() if not Debounce then Debounce = true tool.Parent.Humanoid.Jump = true wait(0.1) local Train = game.ReplicatedStorage.Train:Clone() local Weld = Instance.new("Weld") Train.Parent = game.Workspace Weld.Parent = Train Train.Position = tool.Parent.Torso.Position Train.Orientation = tool.Parent.Torso.Orientation Weld.Part0 = Train Weld.Part1 = tool.Parent.Torso Train.Touched:Connect(function(hit) local humanoid = hit.Parent:WaitForChild("Humanoid") if hit:IsA("BasePart") and not humanoid.Parent then hit:Destroy() end end) game:GetService("Debris"):AddItem(Train,20) game:GetService("Debris"):AddItem(Weld,20) wait(5) Weld:Destroy() wait(WaitTime) Debounce = false end end)
this should work, replaced waitforchild with findfirstchild, put that in an if statement, and also made the if after that if there is a humanoid, not humanoid.parent. Humanoid is set to nil every hit also so that it resets before going onto the next part.
local tool = script.Parent local Debounce = false local WaitTime = 30 tool.Activated:Connect(function() if not Debounce then Humanoid = nil Debounce = true tool.Parent.Humanoid.Jump = true wait(0.1) local Train = game.ReplicatedStorage.Train:Clone() local Weld = Instance.new("Weld") Train.Parent = game.Workspace Weld.Parent = Train Train.Position = tool.Parent.Torso.Position Train.Orientation = tool.Parent.Torso.Orientation Weld.Part0 = Train Weld.Part1 = tool.Parent.Torso Train.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local humanoid = hit.Parent:FindFirstChild("Humanoid") end if hit:IsA("BasePart") and not humanoid then hit:Destroy() end end) game:GetService("Debris"):AddItem(Train,20) game:GetService("Debris"):AddItem(Weld,20) wait(5) Weld:Destroy() wait(WaitTime) Debounce = false end end)