Como hacer un comando de evento simple: Comando de Agua y Tacos

Este es mi primer tutorial en el cual haremos un sistema donde un comando [ !event water ] va a generar agua en el terreno de juego y desaparecerá automáticamente a los 10 segundos. Si nos alcanza el tiempo podriamos añadirle tacos!

Paso 1: Crear el Bloque

  • En Workspace, inserta un Part.
  • Escálalo como quieras (será el molde del agua).
  • Nómbralo WaterBlock.
  • Asegúrate de que esté Anchored = true. — Esto para que no se mueva.
  • Asegúrate de que esté Cancollide= vacio. —> Importante para no golpearnos la cabeza.
  • Poner Tranparency = 1. —> Para que sea completamente invisible
  • Lo puedes pintar como gustes, yo puse de color azul

Paso 2: Script dentro del Bloque

Inserta un Script dentro de WaterBlock y pega este código:

local terrain = workspace.Terrain
local block = script.Parent
local waterOn = false ---Esto es el estado actual del bloque

local function toggleWater()
	if waterOn then
		-- Si ya hay agua lo vaciamos
		terrain:FillBlock(block.CFrame, block.Size, Enum.Material.Air)
		waterOn = false
	else
		-- Si está vacío, lo llenamos de agua
		terrain:FillBlock(block.CFrame, block.Size, Enum.Material.Water)
		waterOn = true
	end
end

-- Esta parte nos devolvera el estado de agua a aire
while true do
	toggleWater()
	task.wait(10)   ----Esto significa que dentro de 10 segundos se cambiara de agua a aire
end

Paso 3: Mover el Bloque a ServerStorage

  • Arrastra tu WaterBlock desde Workspace a ServerStorage.
  • Así mantenemos nuestro espacio limpio y podremos clonarlo cuando sea necesario.

Paso 4: Script del Comando

En ServerScriptService, inserta un Script y pega:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local waterBlock = ServerStorage:WaitForChild("WaterBlock") --Esto hace referencia a nuestro bloque que movimos a ServerStorage

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg:lower() == "!event water" then   ---Aqui esta nuestro comando XD
			
			local clone = waterBlock:Clone()
			clone.Parent = workspace                             ---Aqui esta donde se clonara nuestro bloque 
			clone.Position = Vector3.new(0, 0, 0)

			-- Eliminar después de 11 segundos
			Debris:AddItem(clone, 11)  --- Este numero puede ser igual o mayor al script del bloque
		end
	end)
end)

Resultado :sparkles::sparkles:

  • Puedes generar agua con un simple comando.
  • El agua desaparece sola después de un tiempo.
  • El bloque en ServerStorage sirve como molde reutilizable.

Adicional

Podemos hacer un evento de tacos, colocando un modelo de taco en ServerStorage y el siguiente script en ServiceScriptService

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")
local ServerStorage = game:GetService("ServerStorage")
local Lighting = game:GetService("Lighting")

local TacoModel = ServerStorage:WaitForChild("Taco") -- tu taco MeshPart o modelo

local tacoConnection
local rainbowConnection
local raining = false
local originalLighting = {}
local tacoSound

local function saveLighting()
	originalLighting = {
		Ambient = Lighting.Ambient,
		ColorShift_Top = Lighting.ColorShift_Top,
		ColorShift_Bottom = Lighting.ColorShift_Bottom
	}
end

local function restoreLighting()
	if rainbowConnection then
		rainbowConnection:Disconnect()
		rainbowConnection = nil
	end
	if originalLighting then
		Lighting.Ambient = originalLighting.Ambient
		Lighting.ColorShift_Top = originalLighting.ColorShift_Top
		Lighting.ColorShift_Bottom = originalLighting.ColorShift_Bottom
	end
end

local function startTacoRain()
	if raining then return end
	raining = true

	saveLighting()
	local hue = 0
	rainbowConnection = RunService.Heartbeat:Connect(function()
		hue = (hue + 0.01) % 1
		Lighting.Ambient = Color3.fromHSV(hue, 1, 0.7)
		Lighting.ColorShift_Top = Color3.fromHSV((hue + 0.5) % 1, 1, 1)
	end)

	tacoSound = Instance.new("Sound")
	tacoSound.SoundId = "rbxassetid://142376088"
	tacoSound.Looped = true
	tacoSound.Volume = 1
	tacoSound.Parent = workspace
	tacoSound:Play()

	tacoConnection = RunService.Heartbeat:Connect(function()
		if math.random() < 0.1 then
			local tacoClone = TacoModel:Clone()
			tacoClone.Parent = workspace
			
			local dropPos = Vector3.new(
				math.random(-100, 100),
				50, -- altura
				math.random(-100, 100)
			)

			if tacoClone:IsA("Model") and tacoClone.PrimaryPart then
				tacoClone:SetPrimaryPartCFrame(CFrame.new(dropPos))
			elseif tacoClone:IsA("BasePart") then
				tacoClone.Position = dropPos
			end

			local fallPart = tacoClone.PrimaryPart or tacoClone
			if fallPart then
				local bodyVelocity = Instance.new("BodyVelocity")  ---Le damos caida
				bodyVelocity.MaxForce = Vector3.new(0, math.huge, 0)
				bodyVelocity.Velocity = Vector3.new(0, -60, 0)
				bodyVelocity.Parent = fallPart
			end

			Debris:AddItem(tacoClone, 5)
		end
	end)

	task.delay(60, function()  ---Para detener el evento
		if raining then
			stopTacoRain()
		end
	end)
end

function stopTacoRain()  ---Funcion que detiene el evento
	if not raining then return end
	raining = false
	if tacoConnection then
		tacoConnection:Disconnect()
		tacoConnection = nil
	end
	if tacoSound then
		tacoSound:Stop()
		tacoSound:Destroy()
		tacoSound = nil
	end
	restoreLighting()
	
	for _, obj in ipairs(workspace:GetDescendants()) do
		if obj:IsA("MeshPart") and obj.Name == "Taco" then
			obj:Destroy()
		end
	end

end

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg:lower() == "!event tacos" then   ---Nuestro comando
			startTacoRain()
		end
	end)
end)

Y nos deberia quedar algo asi.

Puedes crear tus propios eventos, no hay limites!

Recuerda que no se necesita ser un gran experto para ser un gran desarrollador :wink:

8 Likes

muyy buennn tutorialll!! me sirvioo bastante :flexed_biceps: :flexed_biceps:

3 Likes