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

This script keeps only going to one part despite anything. Help?

it's a real simple script (i'm probably dumb xD) but it's supposed to (if the player has enough tickets) give the player 1 R$ but it keeps giving me "no u" in the output

local tickets = game.Players.LocalPlayer.Data.tix.Value
local rbux = game.Players.LocalPlayer.Data.robux.Value

script.Parent.MouseButton1Click:connect(function()
	if tickets < 21 then
		print("no u")
	else if tickets >= 21 then
		tickets = tickets - 21
		rbux = rbux + 1
		end
	end
end)

2 answers

✓ Accepted answer

Hi darkblooood,

The solution to your question is a simple one. You set a variable to the amount of tickets, instead of doing that, you need to set it to the value and then get the amount later so it gets updated each time. It may sound complicated but, it's not. You basically made the variable equal to a number, and you didn't change the variable since so it's going to keep thinking the variable's less than 21, since it is. Here, this is what you're basically doing.

####Assuming the tix value at first is 0, and then it slowly becomes 21 somehow.

local tickets = 0; -- This is what you're setting it to. Instead of this, you need to set it to the userdata value and then check for the value each time so you get the most updated version.

script.Parent.MouseButton1Click:connect(function()
	if tickets < 21 then
		-- It will always be lower than 21 because the variable is set to 0 and it never changes. That's what you're basically doing.
	end
end)

##Here is how it should be:

local tickets = game.Players.LocalPlayer.Data.tix -- As you can see, it's the userdata value(The object) instead of the value of the object.
local rbux = game.Players.LocalPlayer.Data.robux -- Same thing here since you're trying to change properties, you need to address the property in the script rather than just change the variable rbux. 

script.Parent.MouseButton1Click:connect(function()
    if tickets.Value < 21 then
        print("no u")
    else if tickets.Value >= 21 then
        tickets = tickets - 21
        rbux.Value = rbux.Value + 1
        end
    end
end)

##Well, I hope I helped. I know it may seem a bit complicated but believe me, it's really not.

Thanks,

Best regards,

~~ KingLoneCat

2 comments

0

AYYYYYYYYYY LONE CATTTTTT!!!!! HAI MY DUUDE

0

What's up?

Press test, then change the value of the tickets to above 21

7 comments

0

they're at like 10000 right now

0

He said it won't work despite anything. So, I'm going to assume he's already tried that.

0

Thanks KingLoneCat!

0

No problem.

0

EDIT: I had to change tickets to tickets.value not sure if you forgot that but the rest worked c:

0

If you make the variable equal to tickets.Value, it will have the same problem. Just check for the value at the if statement like I did.

0

nah I meant tickets = tickets - 21 would be tickets.value = tickets.value - 21 and it works perfectly

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