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

how do i use the scripts parents name for this?

script.Parent.MouseButton1Click:connect(function(p)
	local m = script.Parent.Name
	game.Workspace.mapvals.m.Value = game.Workspace.mapvals.m.Value + 1
	script.Parent.Parent.Visible = false
end)

the scripts parent's name changes according to the value i want to add 1 to. in the output it says:

M is not a valid member of Folder

the folder contains the values. so how do i have it add to the value that has the same name as the scripts parent's name?

1 answer

✓ Accepted answer

You can loop through and check if it matches any of the names you gave it.

for i, v in pairs (script.Parent) do
	if v.Name == "Name1" or v.Name == "Name 2" or v.Name == "Name 3" then
		-- Do stuff
		break
	end
end

I may have misunderstood. You can use FindFirstChild if you're trying to find something that matches the variable, otherwise it will look for something with the name 'M':

script.Parent.MouseButton1Click:connect(function(p)
	local m = script.Parent.Name

	if game.Workspace.mapvals:FindFirstChild(m) then
		game.Workspace.mapvals:FindFirstChild(m).Value = game.Workspace.mapvals:FindFirstChild(m).Value + 1
		script.Parent.Parent.Visible = false
	end
end)

3 comments

0

so theres no way to do this with the actual name it has? becuase i have alot of names for the image button that are going to change.

0

thank you

0

No problem.

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