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

code doesnt run when I touch the brick?

Asked by 5 years ago
Edited 5 years ago

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.

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. SodaZere 31 — 5y
0
try changing #playerss.Playing:GetPlayers() to #(game.Players:GetPlayers()) User#22604 1 — 5y
0
Did you misspell "Spectating"? Is that why it isn't working? (1-Up?) DeceptiveCaster 3761 — 5y
0
Is the team name "Spectating" and not "Specating"? DeceptiveCaster 3761 — 5y
0
/\ no its not it. I misspelled it in the team in the team folder in the explorer as well cause i was tired. SodaZere 31 — 5y

2 answers

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago

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

0
I changed it but it still doesn't work SodaZere 31 — 5y
0
You changed to a team name that exists on your game? (child of the Teams Folder) Leamir 3138 — 5y
0
yes SodaZere 31 — 5y
Ad
Log in to vote
-3
Answered by 5 years ago

your code is disabled.

0
Its not. I put a print just before the if statement and it did print. Its an issue with my if statement. SodaZere 31 — 5y
1
lol DaCrazyDev 444 — 5y
1
oof TheluaBanana 946 — 5y

Answer this question