Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

code doesnt run when I touch the brick?

code:

local teams = game:GetService("Teams"):GetTeams()
local playerss = game.Teams
local function touched (hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if #playerss.Playing:GetPlayers() ~= 0 then
		for i, v in pairs(game.Teams["Specating"]:GetPlayers()) do
			v.TeamColor = BrickColor.new('Navy blue') -- Change it with the color you set the team with(ex. BrickColor.new("Really Black")
			v.Character.Head:Destroy()
			print('k')
		end
	end
 end

script.Parent.Touched:Connect(touched)

When you touch this brick it is supposed to run the code in the if statements but the player doesn't die, the teams don't change, and it wont even print 'k'.

Edit: somebody pointed out my code had a wrong team name. I fixed it but it still doesn't work.

5 comments

0

I put a print just before the if and it did print when I touched the brick so it runs but there is an issue.

0

try changing #playerss.Playing:GetPlayers() to #(game.Players:GetPlayers())

0

Did you misspell "Spectating"? Is that why it isn't working? (1-Up?)

0

Is the team name "Spectating" and not "Specating"?

0

/\ no its not it. I misspelled it in the team in the team folder in the explorer as well cause i was tired.

2 answers

Hello, FlappyCowWMI!

The only error I see here is (probally) the team name, try checking it...

local teams = game:GetService("Teams"):GetTeams()
local playerss = game.Teams
local function touched (hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if #playerss.Playing:GetPlayers() ~= 0 then
        for i, v in pairs(game.Teams["Insert Team Name Here"]:GetPlayers()) do --The error is here, plase place the correct team name...
            v.TeamColor = BrickColor.new('Navy blue') -- Change it with the color you set the team with(ex. BrickColor.new("Really Black")
            v.Character.Head:Destroy()
            print('k')
        end
    end
 end

script.Parent.Touched:Connect(touched)

Good Luck with your games

3 comments

0

I changed it but it still doesn't work

0

You changed to a team name that exists on your game? (child of the Teams Folder)

0

yes

your code is disabled.

3 comments

0

Its not. I put a print just before the if statement and it did print. Its an issue with my if statement.

1

lol

1

oof

This discussion is preserved as it was. New answers, comments, and votes are closed.