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

how do i use the scripts parents name for this?

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
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

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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)

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. theCJarmy7 1293 — 8y
0
thank you theCJarmy7 1293 — 8y
0
No problem. Pyrondon 2089 — 8y
Ad

Answer this question