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

Why does it not change my team when I touch the block?

Asked by 6 years ago
local team = game.Teams.Lobby
local function ontouch(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    local players = game.Players:GetChildren()
    if players then
    if hum then
        players.Teams = game.Teams.Lobby
        hum.Health = 0
        end
    end
end
script.Parent.Touched:connect(ontouch)

IDK whats the problem here.

2 answers

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

You added an s to the property Team. It's also best to use GetPlayerFromCharacter, as it's shorter.

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) --gets the players' character
    if player then --if the player touched it then
    player.Team = game.Teams.Lobby --change the team
    player.Character.Humanoid.Health = 0 --get the humanoid and set it's health to 0
else return end
end)

Please accept my answer if this helped!

Ad
Log in to vote
0
Answered by
Aethys 0 Donator
6 years ago

You need to define the actual player, not just list. Team should be TeamColor

local team = game.Teams.Lobby
local function ontouch(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    local player = game.Players:findFirstChild(hum.Parent.Name)
    if hum then
        if player then
            player.TeamColor = team.TeamColor
            hum.Health = 0
        end
    end
end
script.Parent.Touched:connect(ontouch)

That will change the Team of the player who touches the brick.

Let me know if this isn't the solution you were looking for.

0
You could just use player.Team = team PyccknnXakep 1225 — 6y
0
so like player.team = team? duckyo011 36 — 6y

Answer this question