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

When parts with a certain name touch each other to trigger a function?

Asked by
Roytt 64
8 years ago

Here is a short example, this script won't work and I can't figure out why:

local a = script.Parent.Value.Value
script.Parent.Touched:connect(function(hit)
    if hit.Name == "cho" then
        a = a + 1
        wait()
    end
end)

the value won't increase no matter how many times "cho" touches the Part with the script.

2 answers

Log in to vote
1
Answered by 8 years ago

I also had this problem. To put it simply: you cannot write to a variable that is assigned to a property.

Instead of this...

x = game.StarterGui.Gui.Frame.Text
x = "Hello"

Do this...

x = game.StarterGui.Gui.Frame
x.Text = "Hello"

Likewise,

local a = script.Parent.Value
script.Parent.Touched:connect(function(hit)
    if hit.Name == "cho" then
        a.Value = a.Value + 1
        wait()
    end
end)

Ad
Log in to vote
1
Answered by
rexbit 707 Moderation Voter
8 years ago

Your problem is that you can't add your number value's value in a variable,


local a = script.Parent.Value
script.Parent.Touched:connect(function(hit)
    if hit.Name == "cho" then
        a.Value = a.Value + 1
        wait()
    end
end)

0
What do you mean? Value is the default name of the numValue so Value.Value would refer to the numValue's Value, or am I wrong? Roytt 64 — 8y
0
Oh I now get it, thanks! Roytt 64 — 8y

Answer this question