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

Simple adding script?

Add a simple part into the Workspace. Inside that part add a ClickDetector. Inside that ClickDetector add an IntValue and a Script.

Now write this in the script:

script.Parent.MouseClick:connect(function()
	local X = script.Parent.Value.Value
	if X == 1 then
		X = X + 1
	end
end)

I thought this would add 1 to the IntValue the first time you click the part, but it doesn't. Why not?

4 comments

0

Please Accept the script if it is the answer!

0

Please don't spam the answer comments with this right after you give an answer. I haven't even been online to read it until now.

0

I left this comment 15 minutes after I answered. I usually don't do that unless someone upvotes or the asker comments on my answer. If you take to long then I'll also do that.

0

Maybe in the future wait a little longer than that to give time for the asker to actually get online. For example, in my case I asked this question, went to school, and then returned home and read your answer.

1 answer

✓ Accepted answer

The problem is the variable. Since the variable is property it becomes sort of "read only". You can't change the property through the variable X. You may change the ObjectValues's property if it's a variable. So that means that you can do this:

script.Parent.MouseClick:connect(function()
    local X = script.Parent.Value --Object Value
    if X.Value == 1 then --script.Parent.Value.Value is "1" then...
        X.Value = X.Value + 1 --script.Parent.Value.Value = script.Parent.Value.Value+1.
    end
end)

1 comment

0

Oh, I see. So what you are saying is that properties of objects can't be assigned variables to change them? Thanks! I didn't know that!

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