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)

2 comments

0

Your script looks good!

0

Thanks