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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago

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

Answer this question