Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Train appears to not destroy parts, wondering why?

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)

4 comments

0

Is the script server-sided or client-sided? If it's client sided it won't work. Try using RemoteEvents and clone the train in the server.

0

And add a disabled script inside the train that makes it destroy parts. Then enable the script once you clone the train.

0

Its a server script

0

it might be cus of this local humanoid = hit.Parent:WaitForChild("Humanoid") your waiting for humanoid that might not even be inside of the part and if there is a hum it will also stil not work cus of the not humanoid.Parent which is the part

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.