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

I cannot make my block platform update. Any ideas?

Asked by 4 years ago

I have created a script where the platform will turn red when a vehicle is present on it. This is to prevent unwanted spamming and such. The problem is that while the platform detects the presence of a vehicle on top of it, it cannot revert back to its original color afterwards (when there isn't a vehicle on it). It is only reverted back when a non-child touches it, but I want it so that it updates automatically without such.

function onTouch(object)
    local Vehicle = object.Parent:FindFirstChild("VehicleSeat")
    if (Vehicle ~= nil) then
script.Parent.BrickColor = BrickColor.Red()
    elseif (Vehicle == nil) then 
        script.Parent.BrickColor = BrickColor.Gray()
    end
end


game.workspace.Part.Touched:Connect(onTouch)
0
Hey, if this help you, you can help me back by accept my answer. Block_manvn 395 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Here is your problem: This code will run when something is touch it, but it won't run when something not touch it anymore. So the solution is using TouchEnded event for this. Like the name said, this event will fire when something not touch it anymore.

  • Script:
local function onTouch(object)
    local Vehicle = object.Parent:FindFirstChild("VehicleSeat")
    if Vehicle then
        script.Parent.BrickColor = BrickColor.Red()
    end
end

local function endTouch(object)
    local Vehicle = object.Parent:FindFirstChild("VehicleSeat")
    if not Vehicle then
        script.Parent.BrickColor = BrickColor.Gray()
    end
end

game.workspace.Part.Touched:Connect(onTouch)
game.workspace.Part.TouchEnded:Connect(endTouch)

Hope this help you.

0
I have tried different ways and i think that what would be best for now is for me to just have invisible blocks surrounding the platform that turn the platform color gray for me brickzay 0 — 4y
Ad

Answer this question