So, I have this stage script and it used to work fine but for some reason it doesnt work anymore.
function ot(hit) if hit.Parent ~= nil then local player = game.Players:playerFromCharacter(hit.Parent) if player ~= nil then if player.leaderstats.Stage.Value == script.Parent.Name - 1 then --This is the line of code that is weird. It doesnt seem like it would work, but it used to. Whats wrong with it, and how do i fix it? local h = hit.Parent:FindFirstChild("Humanoid") if h ~= nil then if h.Health ~= 0 then player.leaderstats.Stage.Value = script.Parent.Name end end end end end end script.Parent.Touched:connect(ot)
It's attempting to take a string, script.Parent.Name
, and subtract 1 from it. Lua won't let you perform math (arithmetic) on strings. You must first convert it to a number:
if player.leaderstats.Stage.Value == tonumber(script.Parent.Name) - 1 then