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

Simple adding script? [closed]

Asked by
emite1000 335 Moderation Voter
9 years ago

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?

0
Please Accept the script if it is the answer! EzraNehemiah_TF2 3552 — 9y
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. emite1000 335 — 9y
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. EzraNehemiah_TF2 3552 — 9y
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. emite1000 335 — 9y

Locked by EzraNehemiah_TF2 and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by 9 years ago

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)

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! emite1000 335 — 9y
Ad