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

How do I make this script apply to a certain team only?

How do I make this script apply to a certain team only? I would be very thankful if anybody can help out!

	local UIS = game:GetService('UserInputService')
	local plr = game.Players.LocalPlayer
	local Char = plr.Character or plr.CharacterAdded:Wait()
	 
	 
	local Key = 'Q' --Change this to Desired Letter.
	 
	UIS.InputBegan:Connect(function(Input, IsTyping)
	    if IsTyping then return end
	    local KeyPressed = Input.KeyCode
	    if KeyPressed == Enum.KeyCode[Key] then
	        print(plr.Name..' has pressed '..Key)
	        game.StarterPack.Sound:Play() --Make sure that your Sound is named 'Sound' and inside the Workspace.
	    end
	end)

1 answer

All you'd have to do is use an if statement to check their team.

Like so:

local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()


local Key = 'Q' --Change this to Desired Letter.

UIS.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end
    local KeyPressed = Input.KeyCode
    if KeyPressed == Enum.KeyCode[Key] and plr.Team == game.Teams.Team1 then
        print(plr.Name..' has pressed '..Key)
        game.StarterPack.Sound:Play() --Make sure that your Sound is named 'Sound' and inside the Workspace.
    end
end)

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