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

Strange Method Problem

Asked by 10 years ago

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

Log in to vote
3
Answered by 10 years ago
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)
1
Hope i helped :) Hippalectryon 3 — 10y
0
Thankyou - That was very useful. Protoduction 216 — 10y
0
Remember to click "Accept Answer" if it helped you. Aethex 256 — 10y
0
I did! Protoduction 216 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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

FindFirstChild

or

game.Players["Owenrules12"]

Answer this question