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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

0
AYYYYYYYYYY LONE CATTTTTT!!!!! HAI MY DUUDE greatneil80 2647 — 6y
0
What's up? KingLoneCat 2642 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

0
they're at like 10000 right now VeryDarkDev 47 — 6y
0
He said it won't work despite anything. So, I'm going to assume he's already tried that. KingLoneCat 2642 — 6y
0
Thanks KingLoneCat! VeryDarkDev 47 — 6y
0
No problem. KingLoneCat 2642 — 6y
View all comments (3 more)
0
EDIT: I had to change tickets to tickets.value not sure if you forgot that but the rest worked c: VeryDarkDev 47 — 6y
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. KingLoneCat 2642 — 6y
0
nah I meant tickets = tickets - 21 would be tickets.value = tickets.value - 21 and it works perfectly VeryDarkDev 47 — 6y

Answer this question