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

How would I make it so when a player touches a brick, another one spawns in next to it?

Asked by 4 years ago
Edited by Ziffixture 4 years ago

I want to make a mechanical bridge. For example, if you are across the river and there is a block beside you, by touching the block, it spawns the bridge to walk over said river.

I've asked this question before, and I don't know if I am doing it right. I am new to Lua, and this is the program I currently have, I am not even sure if this is the proper approach, or if it works at all.

local canSpawnBrick = true
local cooldown = 5
local spawnPosition = Vector3.new(0, 10, 0) 

local function onTouched(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid and canSpawnBrick == true then 
        local newBrick = Instance.new("Part") 
        newBrick.Position = spawnPosition
        newBrick.Parent = workspace
        canSpawnBrick = false 
        wait(cooldown)
        canSpawnBrick = true
    end
end

script.Parent.Touched:Connect(onTouched)
0
Your script looks good! AntiWorldliness 868 — 4y
0
Thanks Scallywagpugzy 0 — 4y

Answer this question