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

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

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

✓ Accepted answer

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)

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)

2 comments

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?

0

Oh I now get it, thanks!

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