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

I can't change my IntValue by script properly?

Asked by 6 years ago
Edited 6 years ago

I recently came up with troubles trying to change an IntValue in one of my GUI's to be equal to a shirt ID. here is the script:

local vlu = game.StarterGui.ScreenGui.Shop.ScrollingFrame.Frame.ImageButton.ID.Value
script.Parent.ClickDetector.MouseClick:connect(function()
    vlu = 912196966
end)

And my GUI script:

local itemID = script.Parent.ID.Value
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:connect(function()
    game:GetService("MarketplaceService"):PromptPurchase(player, itemID) 
end)

For some odd reason, it does not work, could anyone tell me why? Thanks, Y.C.

2 answers

Log in to vote
0
Answered by
ee0w 458 Moderation Voter
6 years ago

Very common mistake. You're setting the variable to the value, not the object itself. So when you're changing it, it changes the variable but not the actual value itself. Think of it this way;

local test = workspace.IntValue.Value -- This sets the *variable* to the IntValue's Value.
test = 10 -- This changes the variable, not the value itself. This is a very common mistake.

local test2 = workspace.IntValue -- This targets the IntValue itself.
test2.Value = 10 -- This will target the IntValue's Value, allowing you to change it.

TL;DR: Don't set a variable to .Value. You edit the .Value later on.

(also what Denny said, but too lazy to quote him.)

Ad
Log in to vote
0
Answered by 6 years ago

You need to add 'rbxassetid://' before the number. Numbers only won't work.

Line 3 would be something like this :

vlu = 'rbxassetid://912196966'
0
I forgot to add my GUI, I'll put it in, in a second, but I am using marketplaceservice. It works without the rbxassetid://. YouCheater 15 — 6y
0
Oh whoops, I misread your question. I think the problem is that you're trying to change the value in StarterGui. So in the second script, it won't see the change as the player's PlayerGui wasn't affected. User#20279 0 — 6y
0
Well, the issue is the value is not changing at all, it just stays at zero. When I click the torso (where the click detector is), nothing happens to the value. YouCheater 15 — 6y

Answer this question