Untitled
unknown
plain_text
10 months ago
1.6 kB
4
Indexable
local block = script.Parent
local ServerStorage = game:GetService("ServerStorage")
local carsFolder = ServerStorage:WaitForChild("Cars")
-- Cambiar este número (1-4) dependiendo de qué bloque sea
local CarNumber = 1 -- Cambia a 2, 3, o 4 para los otros bloques
-- Material original del bloque
local originalMaterial = block.Material
-- Variable para controlar si ya hay un carro spawneado
local hasSpawnedCar = false
local spawnedCar = nil
local function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and not hasSpawnedCar then
-- Cambiar apariencia del bloque
block.Material = Enum.Material.Neon
-- Spawning del carro
local carModel = carsFolder:WaitForChild("Car" .. CarNumber)
if carModel then
spawnedCar = carModel:Clone()
spawnedCar.Parent = workspace
spawnedCar:PivotTo(block.CFrame * CFrame.new(0, 3, 0))
hasSpawnedCar = true
-- Conectar evento para detectar cuando el carro es destruido
spawnedCar.AncestryChanged:Connect(function(_, parent)
if parent == nil then
hasSpawnedCar = false
spawnedCar = nil
end
end)
end
end
end
local function onTouchEnded(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
-- Restaurar apariencia original
block.Material = originalMaterial
end
end
block.Touched:Connect(onTouched)
block.TouchEnded:Connect(onTouchEnded)Editor is loading...
Leave a Comment