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

Strange Method Problem

I'm making a Terminal and you have to touch a part to activate it. I know why my code isn't working - It's because 'playername' isn't a child of Players. What I am trying to do is make the part that touched the capture point be put into a string and the value of the string is what is searches for in 'game.Players'. There is a String inside the parent of the script that the name appears in when you step on it.

cap = script.Parent
playername = script.Parent.PlayerName
playersname = playername.Value

while true do
cap.Touched:connect(function(player)

script.Parent.PlayerName.Value = player.Parent.Name
local Touchy = game.Players.playersname
	
	if Touchy.TeamColor == BrickColor.new("Bright red") then
		print "Raider"
	end
end)
wait(0.5)
end

Please help.

2 answers

✓ Accepted answer
cap = script.Parent
playername = script.Parent.PlayerName

-- no while here, due to how events work
cap.Touched:connect(function(player)
playername.Value = player.Name
local Touchy = game.Players:findFirstChild(playername.Value) -- use the FindFirstChild method
if not Touchy then print('No player found') return end
	if Touchy.TeamColor == BrickColor.new("Bright red") then
	        print "Raider"
   	end
end)

This having been said, you don't need a stringValue for that: just use

cap = script.Parent
playername = script.Parent.PlayerName

cap.Touched:connect(function(player)
	if player == BrickColor.new("Bright red") then
	        print "Raider"
   	end
end)

4 comments

1

Hope i helped :)

0

Thankyou - That was very useful.

0

Remember to click "Accept Answer" if it helped you.

0

I did!

To find a player with a name matching the specific string you've got, you must either use

FindFirstChild

or

game.Players["Owenrules12"]

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