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.)

01local RanksAllowed = {team1,team2,team3}
02local debounce = false
03 
04local team1 = game.Teams.Team1
05local team2 = game.Teams.Team2
06local team3 = game.Teams.Team3
07print(RanksAllowed[2])
08script.Parent.Touched:Connect(function(hit)
09    if hit.Parent.Humanoid ~= false then
10        local function findPlayerTeam(player)
11            local player = player
12            print(player.Team)
13        end
14        if findPlayerTeam(hit.Parent).Team == RanksAllowed then
15            print("duck, quack quack")
16        end
17        end
18end)

1 answer

Log in to vote
0
Answered by 5 years ago
01local Players = game:GetService("Players")
02local part = script.Parent
03local RanksAllowed = {game.Teams.Team1, game.Teams.Team2}
04 
05local function onTouched(part)
06    local player = Players:GetPlayerFromCharacter(part.Parent)
07    if not player then return end
08    for i,v in pairs(RanksAllowed) do
09        if player.Team == v then
10        print("Player is on the right team")
11        end
12    end
13end
14part.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