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

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

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

✓ Accepted answer
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

3 comments

0

Okay, thanks! But it's printing even if I'm on the incorrect team.

0

yea i noticed the team was assigned different than what I was in. seems like roblox messed the team system up

0

Oh.

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