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

How to I make a smashable fence? [SOLVED BY MYSELF]

Asked by 10 years ago

The fence will be one part, not in a model. I need help making the fence unanchor itself when it is hit at a certain speed by anything. Also for it to uncollide it self 5 seconds after it's hit, and also respawn 50 seconds later after it is hit in the exact position it was before it was hit. This would be a lot of help for me since I am just now learning to script.

6 answers

Log in to vote
1
Answered by 10 years ago

Remember not to post things that ask to write the script. I'll give you a layout but I won't write it for you.

First, I would make the surfaces glue or studs or something so that it breaks when under enough stress, not unanchor itself. This means you have to unanchor the whole thing so it breaks.

Next, simply write a line that changes the property after 5 seconds (script.Parent.CanCollide = false).

Finally, put a clone of it in lighting in the same location, and clone it into workspace after 50 seconds.

Hopefully this will help.

Ad
Log in to vote
0
Answered by 10 years ago

I could possibly answer this but I'm not sure about it being hit at a certain speed, is this going to be hit by the player or a object (for example your in a car and you go full speed ahead on the fence)

0
It should activate when hit by any part. austint30 5 — 10y
Log in to vote
0
Answered by
neoG457 315 Moderation Voter
10 years ago

Well basically you have to click surfaces in the top right corner of the new studio and the click "add weld" Then put it on the surface of 1 part of the fence, you then copy it and add the parts to each other, I would say that the effect works better with a brick wall.

0
I dont think thats everything to it but its what I know. neoG457 315 — 10y
Log in to vote
0
Answered by 10 years ago

Forgot trying to do it at a certain speed. Your just trying to be too specific. If you're trying to do this by say a bullet from a gun, rename the bullet something like "fenceCrusher" and then inside of the fence put something along the lines of:

function onHit(part)
    if part.Name == "fenceCrusher" then
        script.Parent.Anchored = false
        local v = Instance.new"BodyVelocity", script.Parent)
        v.velocity = Vector3.new(math.random(1, 5),math.random(1, 5),math.random(1, 5))
        wait(0.5)
        v:Destroy()
        --Optional    script.Parent.CanCollide = false
end
script.Parent.Touched:connect(onHit)
Log in to vote
0
Answered by
Maxomega3 106
10 years ago

You can keep a copy of the fence in ServerStorage for respawning it. As for speed, that would be hard unless the object was a vehicle. Here's my attempt:

script.Parent.Touched:connect (function (hit)
    if hit.Parent:FindFirstChild ('VehicleSeat') then -- check for a vehicle
        if hit.Parent.VehicleSeat.Speed == 50 then -- Speed check, change to fit your needs.
            script.Parent.Anchored = false -- TIMBER!!!
            wait (5)
            script.Parent.CanCollide = false 
            wait (50)
            game.ServerStorage.Fence:Clone ().Parent = Workspace
            script.Parent:Destroy ()
        end
    end
end)
0
I was looking carefully at the script and I think there is something that will not work out. When the fence uncollides itself it will fall into the void before the script could respawn the fence. Maybe it should anchor it again before it goes uncollide, that way when it is lying on the ground with uncollide, that way other drivers don't hit it. austint30 5 — 10y
Log in to vote
0
Answered by 9 years ago

After a looooong time, I have figured it out myself after learning a lot more scripting. Basically what this script does is that when there is an object moving a certain speed through the detection box of a street lamp, it would make the streetlamp invisible and turn it's collisions off, and then clones a streetlamp that is not anchored and falls apart on runtime that is in the ReplicatedStorage. It then places the clone in the streetlamp's position. This gives the illusion that you smashed it.

After 5 seconds, it removes the debris. After 25 seconds, the streetlamp becomes visible again and it's collisions turn back on!

lamp = script.Parent.Parent.Lamp
dupe = game.ReplicatedStorage.BrokenLamp
debounce = true
isBroken = false


function Disappear ()
    local a = lamp:GetChildren()
    local light = script.Parent.Parent.Lamp.Light.PointLight
    if debounce then
    debounce = false

    for i = 1,#a do
        if a[i]:IsA("Part") or a[i]:IsA("TrussPart") or a[i]:IsA("WedgePart") then
            a[i].Transparency = 1
            a[i].CanCollide = false
        end
    end
    light.Enabled = false
    dupe:Clone().Parent = script.Parent.Parent
    isBroken = true
    local lampPos = lamp:GetPrimaryPartCFrame()
    script.Parent.Parent.BrokenLamp:SetPrimaryPartCFrame(lampPos)
    wait(5)
    script.Parent.Parent.BrokenLamp:Destroy()
    wait(25)
    for i = 1,#a do
        if a[i]:IsA("Part") or a[i]:IsA("TrussPart") or a[i]:IsA("WedgePart") then
            a[i].Transparency = 0
            a[i].CanCollide = true
        end

    end
    light.Enabled = true
    wait(0.2)
    debounce = true
    isBroken = false
    end
end

script.Parent.Touched:connect(function(otherPart)
    if(otherPart.Anchored == false and otherPart.CanCollide == true and otherPart.Velocity.magnitude > 50) then
        if (isBroken == false) then
        script.Parent.hit:Play()
        end
        Disappear()
    end
end)

Answer this question