Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

?Confused on one line of code that used to work but now cant perform arithmetic.

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)

2 comments

0

Is Name an IntValue?

0

No, name is just the name of the part. The parts name is 2. This line of code is supposed to tell the game that if your stage is 1 less than this stage, then [code]

1 answer

✓ Accepted answer

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

1 comment

0

Thanks! I didnt know you could do that lol

This discussion is preserved as it was. New answers, comments, and votes are closed.