Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
Is Name an IntValue? PyccknnXakep 1225 — 6y
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] 0HappyManDudeguy0 15 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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
0
Thanks! I didnt know you could do that lol 0HappyManDudeguy0 15 — 6y
Ad

Answer this question