I’m trying to make a mopping system like in those cafe games. I have multiple models of spills for the player to clean up but sometimes it would waste an RNG because the spill already exists. How would I make it so the system rerolls to another spill if the one originally selected has already been spawned? I know it’s fixable with a table but I couldn’t find a post about it. (My brain has already rotted)
My code
local spillsFolder = script.Parent.Spills
local broom = game:GetService("ServerStorage"):WaitForChild("broom")
local event = game.ReplicatedStorage.RemoveInventory
local TweenService = game:GetService("TweenService")
local tInfo = TweenInfo.new(1)
local RNG = Random.new()
local function generateRNG()
local choice = RNG:NextInteger(1, #spillsFolder:GetChildren())
local spill = spillsFolder:GetChildren()[choice]
return spill
end
local function acceptRNG(spillRNG)
spillRNG:FindFirstChild("Main").Transparency = 0
spillRNG:FindFirstChild("Part").Transparency = 0
spillRNG:FindFirstChild("Glass").Transparency = 0.35
spillRNG:FindFirstChild("Proximity").ProximityPrompt.Enabled = true
spillRNG:FindFirstChild("Proximity").ProximityPrompt.Triggered:Connect(function(player)
if player then
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if humanoid.Health > 0 then
local broomClone = broom:Clone()
broomClone.Parent = character
game.Debris:AddItem(broomClone, 1)
humanoid.WalkSpeed = 0
event:FireClient(player)
local fade_tween1 = TweenService:Create(
spillRNG:FindFirstChild("Main"),
tInfo,
{Transparency = 1}
)
local fade_tween2 = TweenService:Create(
spillRNG:FindFirstChild("Part"),
tInfo,
{Transparency = 1}
)
local fade_tween3 = TweenService:Create(
spillRNG:FindFirstChild("Glass"),
tInfo,
{Transparency = 1}
)
fade_tween1:Play()
fade_tween2:Play()
fade_tween3:Play()
spillRNG:FindFirstChild("Proximity").ProximityPrompt.Enabled = false
wait(2.5)
humanoid.WalkSpeed = 16
end
end
end
end
end)
spillRNG.Main.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
if humanoid.Health > 0 and spillRNG.Proximity.CoolDown.Value == false and spillRNG.Main.Transparency == 0 then
spillRNG.Proximity.CoolDown.Value = true
humanoid.WalkSpeed = 0
wait(1)
humanoid.WalkSpeed = 16
wait(1.5)
spillRNG.Proximity.CoolDown.Value = false
end
end
end
end)
end
local function tradeRNG(spillRNG)
end
while wait(5) do
local spillRNG = generateRNG()
if spillRNG.Main.Transparency == 1 then
acceptRNG(spillRNG)
elseif spillRNG.Main.Transparency == 0 then
tradeRNG(spillRNG)
end
end