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

How to detect a players team in a if statement?

I have a door script that works completely fine until I had an if statement on which team the player is in. I've tried and I feel like this would make sense but it doesn't work.

local ts = game:GetService("TweenService")
local tweeninfo2 = TweenInfo.new(3.75)
local goalA = {}
goalA.Position = Vector3.new(-67.107, 14.625, -17.316)
local tweenA = ts:Create(script.Parent, tweeninfo2, goalA)
local goalB = {}
goalB.Position = Vector3.new(-67.107, 21.875, -17.316)
local tweenB = ts:Create(script.Parent,tweeninfo2, goalB)



local opened = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local Team = game:GetService("Teams")["Administrator"]
	if player.Team == Team then
		print(player.Name)
		print(player.Name .. " is an Administrator.")
		opened = true
		script.Parent["Sliding door 2"].Playing = true
		tweenB:Play()
		wait(7)
		script.Parent["Sliding door 2"].Playing = true
		tweenA:Play()
		wait(1)
		opened = false
	end
end)

1 answer

✓ Accepted answer

Might be obvious but try this:

local ts = game:GetService("TweenService")
local tweeninfo2 = TweenInfo.new(3.75)
local goalA = {}
goalA.Position = Vector3.new(-67.107, 14.625, -17.316)
local tweenA = ts:Create(script.Parent, tweeninfo2, goalA)
local goalB = {}
goalB.Position = Vector3.new(-67.107, 21.875, -17.316)
local tweenB = ts:Create(script.Parent,tweeninfo2, goalB)

local opened = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local Team = game:GetService("Teams")
    local Admin_Team = Team:FindFirstChild("Administrator")
    if(Admin_Team == nil) then
	warn("warning!: there is no team named Administrator in the Teams Service! \n ADMINS WHERE ARE YOUS!!!!!")
 
    end
    if player.Team == Admin_Team then
        print(player.Name)
        print(player.Name .." is an Administrator.")
        opened = true
        script.Parent["Sliding door 2"].Playing = true
        tweenB:Play()
        wait(7)
        script.Parent["Sliding door 2"].Playing = true
        tweenA:Play()
        wait(1)
        opened = false
    end
end)

3 comments

0

Its still not working. :/

0

I added a print thing after the function above local Team. To print the players name and it does print it but it doesn't do anything in the if statement

0

Alright for some reason it wasn't working on ROBLOX Studio but it works in ROBLOX player so thank you!

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