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

I can't change my IntValue by script properly?

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

✓ Accepted answer

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.)

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

Line 3 would be something like this :

vlu = 'rbxassetid://912196966'

3 comments

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://.

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.

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.

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