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 choose a part based on a String Value?

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)

3 comments

0

From what I can read the string value that you have has a child that is an int value?

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.

0

so you want a stringvalues, Value to select something in workspace

1 answer

✓ Accepted answer

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

4 comments

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'

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?

0

Ok i got it its BrickColour.Name. Thanks for the help!

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.

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