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

How do i choose a part based on a String Value?

Asked by
PastDays 108
5 years ago
Edited 5 years ago

So basically when a player touches a block it removes a point from brick colours team and gives a point to the person who touched its team, I have a StringValue with the Value as the Team Name meaning i can get the players team from that String value but how would i use that Value to select a thing (An int value in this instance).

function onTouched(hit)

    local Red = game.Workspace.Game_Files.Round.RedNum
    local Blue = game.Workspace.Game_Files.Round.BlueNum
    local Yellow = game.Workspace.Game_Files.Round.YellowNum
    local Team = hit.Parent.Team.Value

    if script.Parent.Color == 'Tawny' then
        Red.Value = Red.Value - 1
    game.Workspace.Game_Files.Round. (This is where i want the String value to be used)
    end
end

connection = script.Parent.Touched:connect(onTouched)

I've tried this but this also doesn't work, giving this error:

Workspace.Floor_Tiles.Column_1.Floor_Tile.Colouring:7: attempt to index a nil value

function onTouched(hit)

    local Red = game.Workspace.Game_Files.Round.RedNum
    local Blue = game.Workspace.Game_Files.Round.BlueNum
    local Yellow = game.Workspace.Game_Files.Round.YellowNum
    local Team = hit.Parent.Team
    local TeamValue = game.Workspace.Game_Files.Round:FindFirstChild(tostring(Team)).Value
    local Colour = hit.Parent.Colour

    if script.Parent.BrickColor == 'Tawny' then
        Red.Value = Red.Value - 1
        TeamValue = TeamValue + 1
        script.Parent.Color =  Colour.Value

    end
end

connection = script.Parent.Touched:connect(onTouched)
0
From what I can read the string value that you have has a child that is an int value? RichCookieGamer 7 — 5y
0
So in the player is a 'StringValue' The Value of that is 'BlueNum' which is a IntValue's Name and i need that IntValues Value, if that makes sense. PastDays 108 — 5y
0
so you want a stringvalues, Value to select something in workspace User#23365 30 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Hi Past,

You can access things by using brackets at their parents, such as:

workspace["Part"];
game["Workspace"]["Player1"];

As you can see, with this method, you are able to use the string. You can also use the string with :FindFirstChild() and :WaitForChild() methods. Like this:

workspace:FindFirstChild("Part");
game:WaitForChild("Workspace"):FindFirstChild("Player1");

So, like that, you are able to make use of the string value to find the part. It would look like this with your script:

function onTouched(hit)

    local Red = game.Workspace.Game_Files.Round.RedNum
    local Blue = game.Workspace.Game_Files.Round.BlueNum
    local Yellow = game.Workspace.Game_Files.Round.YellowNum
    local Team = hit.Parent.Team.Value

    if script.Parent.Color == 'Tawny' then
        Red.Value = Red.Value - 1
    game.Workspace.Game_Files.Round:WaitForChild(Team); 
    end
end

connection = script.Parent.Touched:connect(onTouched)

Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
Well im not sure if its working as this is not firing the script even though the colour is tawny: script.Parent.Color == 'Tawny' PastDays 108 — 5y
0
Ok ok so i changed it to if the reflectance is 0 it fires and it worked so im referencing the brick color wrong you have any idea what i'm doing wrong? PastDays 108 — 5y
0
Ok i got it its BrickColour.Name. Thanks for the help! PastDays 108 — 5y
0
Glad to help. Sorry I didn't know you needed my help, I was answering another question. Just got done answering 4 questions in total, I think I'm satisfied for now. KingLoneCat 2642 — 5y
Ad

Answer this question