You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I am trying to make a game mode with 5 separate buildings, when one of them has the highest amount of health, they win.
What is the issue? Include screenshots / videos if possible!
I am trying to use else/elseifs to find out who has the most health, and if there is at least 2 with the same hp, it ties, but it ignores the else and elseifs and runs the first “if” regardless of it being true or not
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i have tried looking for solutions on the dev hub but none of the solutions work for me
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
(im not the best at scripting so this code is gonna be a big eye sore)
ut = workspace.Map["Undertale Area"]["undertale hitbox"].Humanoid.Health
uf = workspace.Map["Underfell Area"]["underfell hitbox"].Humanoid.Health
ot = workspace.Map["Outertale Area"]["outertale hitbox"].Humanoid.Health
ht = workspace.Map["Horrortale Area"]["horrortale hitbox"].Humanoid.Health
us = workspace.Map["Underswap Area"]["swaptale hitbox"].Humanoid.Health
local numberTable = {uf, ut, ot, ht, us}
local hint = Instance.new"Hint"
local highestnumber = 0
for i, v in pairs(numberTable) do
local number = tonumber(v)
if number > highestnumber then
highestnumber = number
end
end
if highestnumber == ut then
hint.Parent = workspace
hint.Text = "undertale wins!"
wait(5)
hint:Destroy()
elseif highestnumber == uf then
hint.Parent = workspace
hint.Text = "underfell wins!"
wait(5)
hint:Destroy()
elseif highestnumber == ot then
hint.Parent = workspace
hint.Text = "outertale wins!"
wait(5)
hint:Destroy()
elseif highestnumber == ht then
hint.Parent = workspace
hint.Text = "horrortale wins!"
wait(5)
hint:Destroy()
elseif highestnumber == us then
hint.Parent = workspace
hint.Text = "underswap wins!"
wait(5)
hint:Destroy()
else
hint.Parent = workspace
hint.Text = "Tie!"
wait(5)
hint:Destroy()
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Start by sorting your array of healths! This will immediately get you the highest number and if the runner up is the same, then we have a tie! Here is some greater pseudo code you can use to get started.
table.sort(numberTable)
if numberTable[1] == numberTable[2] then
print("Tie!")
else
if numberTable[1] == ut then
-- etc ...
end
end
It didn’t do the same thing, it printed “Tie!”, also this is clearly incorrect code. Use elseif without a space and use roblox’s Format Document to fix the indentation.
i’m sorry I didn’t clarify, first it printed the first thing on the list, before, the first thing was “undertale”, now the first thing on it is “tie!”. and also as i have clearly stated, I’m fairly new to coding. I’m not too familiar with all the steps involved
I am not sure which way the sort sorts 1, 2, 3, 4 or 4, 3, 2, 1. print out the sorted table to see and if it’s 1, 2, 3, 4 (aka ascending) then use the last index instead
if numberTable[5] == numberTable[4] then
print("Tie!")
else
if numberTable[5] == ut then
-- etc ...
elseif numberTable[5] == ot then
-- etc ...
end
end
i think it actually might be an error with the code i wrote before now, the list is showing all of the values at the max health, even though i hurt a few of the buildings.