So I’m trying to make a script that if a layer is on a team it allows them to crouch and if there not on hat team they can not crouch.
Here is my script.
local UserInputService = game:GetService(“UserInputService”)
local Character = script.Parent
local Humanoid = Character:WaitForChild(“Humanoid”)
local isRunning = false
local Animation = Humanoid:LoadAnimation(script:WaitForChild(“Animation”))
local Players = game:GetService(“Players”)
local Teams = game:GetService(“Teams”)
local player
UserInputService.InputBegan:Connect(function(key)
if Players.Team == Teams[“Player”] then
if key.KeyCode == Enum.KeyCode.C then
if not isRunning then
isRunning = true
Animation:Play()
Humanoid.WalkSpeed = 10
else
Animation:Stop()
Humanoid.WalkSpeed = 16
isRunning = false
end
end
end
end)
Any help is appreciated.
This needs to be if Players.LocalPlayer.Team == Teams.Player
Hey, Do you want so if the player presses C they crouch and if they press C again they don’t crouch?
if so here is the script. (make it a local script inside the startercharacterscripts)
local UserInputService = game:GetService("UserInputService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local isRunning = false
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local player = game.Players.LocalPlayer
UserInputService.InputBegan:Connect(function(key)
if Players.Team == Teams.Player then
if key.KeyCode == Enum.KeyCode.C then
if not isRunning then
isRunning = true
Animation:Play()
Humanoid.WalkSpeed = 16
end
end
end
end)
UserInputService.InputEnded:Connect(function(key)
if player.Team == Teams.Player then
if key.KeyCode == Enum.KeyCode.C then
Animation:Stop()
Humanoid.WalkSpeed = 10
isRunning = false
end
end
end)