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

How do I give a green light to players on the green team?

Asked by 7 years ago

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.

01function 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 = Color3.new(0,255,0)
11        end
12    end
13    if (Character:findFirstChild("LowerTorso") == nil) then
14    end
15end
16game.Workspace.ChildAdded:connect(onRespawn)

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Try editing this:

01game.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 = Color3.fromRGB(0, 255, 0);
13            else
14                -- player is not on the green team
15            end
16        end
17    end
18end)
0
Doesn't work. JarFullOfMayonnaise 48 — 7y
0
Answer edited; the value of player.Team is a Team Object, not a string, as I took from your original code. Next time, try editing the code. Fix was simple. KidTech101 376 — 7y
0
I did edit it and I though that was what you were checking for. JarFullOfMayonnaise 48 — 7y
0
Fair enough KidTech101 376 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

This worked. I modified a toolgiver to give pointlights instead, then I put it on the spawnpad.

01local debounce = false
02 
03function getPlayer(humanoid)
04local players = game.Players:children()
05for i = 1, #players do
06if players[i].Character.Humanoid == humanoid then return players[i] end
07end
08return nil
09end
10 
11function onTouch(part)
12 
13local human = part.Parent:findFirstChild("Humanoid")
14if (human ~= nil) and debounce == false then
15 
View all 36 lines...

Answer this question