I'm trying to make players on the green team glow with a green light, but when I do, I get the error "charname is not a valid member of Players". What i'm trying to do is have the script find the name of the player (from the model), then find the corresponding player in game.Players.
01 | function onRespawn(Character) |
02 | if (Character:findFirstChild( "LowerTorso" ) ~ = nil ) then |
03 | local charname = Character.Name |
04 | local playerteam = game.Players.charname.Team |
05 | if playerteam = = "Green" then |
06 | local light = Instance.new( "PointLight" ) |
07 | light.Parent = Character.LowerTorso |
08 | light.Range = 15 |
09 | light.Brightness = 10 |
10 | light.Color = Color 3. new( 0 , 255 , 0 ) |
11 | end |
12 | end |
13 | if (Character:findFirstChild( "LowerTorso" ) = = nil ) then |
14 | end |
15 | end |
16 | game.Workspace.ChildAdded:connect(onRespawn) |
Try editing this:
01 | game.Workspace.ChildAdded:connect( function (child) |
02 | if (child:IsA( "Model" )) then |
03 | local player = game.Players:GetPlayerFromCharacter(child); |
04 | if (player ~ = nil ) then |
05 | -- this model is a character |
06 | if (player.Team = = game.Teams.Green) then |
07 | -- player is on the green team, make them glow |
08 | local light = Instance.new( "PointLight" , child.Torso); |
09 | light.Range = 15 ; |
10 | light.Brightness = 10 ; |
11 | -- Color3.new(r, g, b) takes three parameters between 0 and 1 (percentage of each color) whereas Color3.fromRGB(r, g, b) takes three parameters between 0 and 255 |
12 | light.Color = Color 3. fromRGB( 0 , 255 , 0 ); |
13 | else |
14 | -- player is not on the green team |
15 | end |
16 | end |
17 | end |
18 | end ) |
This worked. I modified a toolgiver to give pointlights instead, then I put it on the spawnpad.
01 | local debounce = false |
02 |
03 | function getPlayer(humanoid) |
04 | local players = game.Players:children() |
05 | for i = 1 , #players do |
06 | if players [ i ] .Character.Humanoid = = humanoid then return players [ i ] end |
07 | end |
08 | return nil |
09 | end |
10 |
11 | function onTouch(part) |
12 |
13 | local human = part.Parent:findFirstChild( "Humanoid" ) |
14 | if (human ~ = nil ) and debounce = = false then |
15 |