Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Train appears to not destroy parts, wondering why?

Asked by 2 years ago

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)
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. T3_MasterGamer 2189 — 2y
0
And add a disabled script inside the train that makes it destroy parts. Then enable the script once you clone the train. T3_MasterGamer 2189 — 2y
0
Its a server script imnotaguest1121 362 — 2y
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 Puppynniko 1059 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

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)
Ad

Answer this question