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

I'm testing out a door script but it's not working, how do I fix it?

Asked by
sngnn 274 Moderation Voter
5 years ago
Edited 5 years ago

I have a script that will print something if a part is stepped on. The object has to have a humanoid to make sure it's a player, and the player has to be on the right team to print it. Here it is, can someone please point out the errors and how to fix it? It won't work (of course.)

local RanksAllowed = {team1,team2,team3}
local debounce = false

local team1 = game.Teams.Team1
local team2 = game.Teams.Team2
local team3 = game.Teams.Team3
print(RanksAllowed[2])
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid ~= false then
        local function findPlayerTeam(player)
            local player = player
            print(player.Team)
        end
        if findPlayerTeam(hit.Parent).Team == RanksAllowed then
            print("duck, quack quack")
        end
        end
end)

1 answer

Log in to vote
0
Answered by 5 years ago
local Players = game:GetService("Players")
local part = script.Parent
local RanksAllowed = {game.Teams.Team1, game.Teams.Team2}

local function onTouched(part)
    local player = Players:GetPlayerFromCharacter(part.Parent)
    if not player then return end
    for i,v in pairs(RanksAllowed) do
        if player.Team == v then
        print("Player is on the right team")
        end 
    end
end
part.Touched:Connect(onTouched)

problem: RanksAllowed was a table so it wasn't getting team names

0
Okay, thanks! But it's printing even if I'm on the incorrect team. sngnn 274 — 5y
0
yea i noticed the team was assigned different than what I was in. seems like roblox messed the team system up RobloxianDestory 262 — 5y
0
Oh. sngnn 274 — 5y
Ad

Answer this question