#my skibidi toilet is broken

9 messages · Page 1 of 1 (latest)

radiant current
#

it wont despawn after it dies

twin zealot
#

Heres a fix:

Dont make skibidi toilet games

lapis fulcrum
#

Can I see the code of the Skibidi Toilet

radiant current
#

cant send it its too long

#

local toilet = script.Parent
local humanoid = toilet:FindFirstChild("Humanoid")
local rootPart = toilet:FindFirstChild("HumanoidRootPart")
local base = workspace:FindFirstChild("Base")

if not humanoid or not rootPart then
error("Toilet is missing Humanoid or HumanoidRootPart!")
end

if not base then
error("Base part is missing in the workspace!")
end

local health = 100
local moveSpeed = 16
local attackRange = 5
local damage = 20
local attackCooldown = 1
local isDead = false
local canAttack = true

local function getNearestPlayer()
local nearestPlayer = nil
local shortestDistance = math.huge

for _, player in pairs(game.Players:GetPlayers()) do
    local character = player.Character
    if character and character:FindFirstChild("HumanoidRootPart") then
        local distance = (rootPart.Position - character.HumanoidRootPart.Position).Magnitude
        if distance < shortestDistance then
            shortestDistance = distance
            nearestPlayer = character
        end
    end
end

return nearestPlayer

end

#

local function attackPlayer(playerCharacter)
if not canAttack then return end

local playerHumanoid = playerCharacter:FindFirstChild("Humanoid")
if playerHumanoid and playerHumanoid.Health > 0 then
    playerHumanoid:TakeDamage(damage)
    print("Toilet attacked the player!")
    canAttack = false
    wait(attackCooldown)
    canAttack = true
end

end
local function attackBase()
if not canAttack then return end

if base and base:IsA("BasePart") then
    print("Toilet attacked the Base!")
    canAttack = false
    wait(attackCooldown)
    canAttack = true
end

end

local function die()
if isDead then return end
isDead = true
print("Toilet has been defeated!")
humanoid:MoveTo(rootPart.Position)
wait(1)
toilet:Destroy()
end

while wait(0.1) do
if isDead then break end

local targetPlayer = getNearestPlayer()
if targetPlayer then
    
    local distanceToPlayer = (rootPart.Position - targetPlayer.HumanoidRootPart.Position).Magnitude
    if distanceToPlayer <= attackRange then
        humanoid:MoveTo(rootPart.Position) 
        attackPlayer(targetPlayer)
    else
        humanoid:MoveTo(targetPlayer.HumanoidRootPart.Position)
    end
else
    
    local distanceToBase = (rootPart.Position - base.Position).Magnitude
    if distanceToBase <= attackRange then
        humanoid:MoveTo(rootPart.Position) 
        attackBase()
    else
        humanoid:MoveTo(base.Position)
    end
end

end

humanoid.Died:Connect(die)

toilet:SetAttribute("TakeDamage", function(damageAmount)
if isDead then return end

health = health - damageAmount
print("Toilet took damage! Remaining health: " .. health)

if health <= 0 then
    die()  
end

end)