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?
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)