Hello, I'm making an auto-stat change script which changes someone rank when they reach a certain amount of XP, I've added a few 'end' lines because when I start a line with "if" it will make me put a 'end' at the end, I don't know if this is the problem, here is the script, the script is in a a part which is stretched across the world, so they are always touching it.
The script is in a normal script, but please help if you can!
local ting = 0 function onTouched(hit) if ting == 0 then ting = 1 check = hit.Parent:FindFirstChild("Humanoid") if check ~= nil then local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") if stats ~= nil then local cash = stats:findFirstChild("Rank") local xp = stats:findFirstChild("XP") if xp.Value == 250 then cash.Value = "Private" elseif xp.Value == 7500 then cash.Value = "Private First Class" elseif xp.Value == 20000 then cash.Value = "Corporal" elseif xp.Value == 21550 then cash.Value = "Warrant Officer 2" elseif xp.Value == 23500 then cash.Value = "Warrant Officer 1" elseif xp.Value == 25000 then cash.Value = "Sergeant" elseif xp.Value == 30000 then cash.Value = "Master Sergeant" elseif xp.Value == 35000 then cash.Value = "Capitan" elseif xp.Value == 36500 then cash.Value = "Second Lieutenant" elseif xp.Value == 37500 then cash.Value = "First Lieutenant" elseif xp.Value == 40000 then cash.Value = "Cononel" elseif xp.Value == 45000 then cash.Value = "Commander" elseif xp.Value == 50000 then cash.Value = "Admarial" elseif xp.Value = 65000 then cash.Value = "Commanding Officer" end end end end end end end end end end end end end end end end end) ting = 0 end end end script.Parent.Touched:connect(onTouched)
You don't want to check if a Player's XP equals a certain amount in order to assign them a rank, because what if they go over that amount?
Instead, check if the player has equal or more XP than what is required for that rank, in order of the highest rank to the lowest rank. For example:
if xp >= 10000 then rank = "Admiral" elseif xp >= 500 then rank = "Colonel" else rank = "Peasant" end
Additionally, you have way too many END statements. You only need END statements for functions, IF and WHILE statements. ELSEIF and ELSE statements "continue" IF statements and don't require their own END.