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.
function onRespawn(Character) if (Character:findFirstChild("LowerTorso") ~= nil) then local charname = Character.Name local playerteam = game.Players.charname.Team if playerteam == "Green" then local light = Instance.new("PointLight") light.Parent = Character.LowerTorso light.Range = 15 light.Brightness = 10 light.Color = Color3.new(0,255,0) end end if (Character:findFirstChild("LowerTorso") == nil) then end end game.Workspace.ChildAdded:connect(onRespawn)
Try editing this:
game.Workspace.ChildAdded:connect(function(child) if(child:IsA("Model"))then local player = game.Players:GetPlayerFromCharacter(child); if(player ~= nil)then -- this model is a character if(player.Team == game.Teams.Green)then -- player is on the green team, make them glow local light = Instance.new("PointLight", child.Torso); light.Range = 15; light.Brightness = 10; -- 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 light.Color = Color3.fromRGB(0, 255, 0); else -- player is not on the green team end end end end)
This worked. I modified a toolgiver to give pointlights instead, then I put it on the spawnpad.
local debounce = false function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if (human ~= nil) and debounce == false then debounce = true local player = getPlayer(human) if (player == nil) then return end local elight = part.Parent.LowerTorso:findFirstChild("PointLight") if (elight == nil) then local light = script.Parent:clone() light.Parent = human.Parent.LowerTorso light.Enabled = true end wait(2) debounce = false end end script.Parent.Parent.Touched:connect(onTouch)