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

I don't know How UserInputService works?

Asked by
Neon_N 104
5 years ago
Edited 5 years ago

The script below is in a StarterCharacterScripts and the other script is in ServerScriptService

--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

--// Varaibles \\--
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Remote = ReplicatedStorage.FireBallEvent
local Mouse = plr:GetMouse()

--// Settings \\--
local Debounce = true
local Key = 'Q'

UserInputService.InputBegan:Connect(function(Input, IsTyping)
 if IsTyping then return end
 local KeyPressed = Input.KeyCode
 if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then
  Debounce = false
  Remote:FireServer(Mouse.Hit)
  wait(1)
  Debounce = true
 end
end)

I understand that this Debounce thing will make a little delay But I don't know how IsTyping prevent players from activating Q while they are chatting.

Other Script:

--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Variables \\--
local Remote = ReplicatedStorage.FireBallEvent

--// Settings \\--
local Damage = 10

Remote.OnServerEvent:Connect(function(plr, Mouse)
 local Char = plr.Character or plr.CharacterAdded:Wait()

 local Part = Instance.new('Part')
 Part.Shape = Enum.PartType.Ball
 Part.Anchored = false
 Part.CanCollide = false
 Part.Transparency = 0.5
 Part.Color = Color3.fromRGB(255,0,0)
 Part.Material = Enum.Material.Neon
 Part.Size = Vector3.new(3,3,3)
 Part.Name = 'FireBall'
 Part.CFrame = Char.HumanoidRootPart.CFrame
 Part.Parent = workspace

 local BodyVelocity = Instance.new("BodyVelocity")
 BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
 BodyVelocity.Velocity = Mouse.lookVector*30
 BodyVelocity.Parent = Part

 local Debounce = true
 Part.Touched:Connect(function(h)
  if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and Debounce then
   Debounce = false   
   local Enemy = h.Parent.Humanoid
   Enemy:TakeDamage(Damage)
   Part:Destroy()
   wait(1)
   Debounce = true
  end
 end)
end)

source : https://www.youtube.com/watch?v=nKh8CWQ6zL0

0
Inputbegan has 2 parameters, input and gameProcessedEvent, the second one is what you have (isTyping), it's a bool that is true if the player is using the chat/a textbox/..., and false if not User#20388 0 — 5y
0
For more information, you can go to this page https://developer.roblox.com/api-reference/event/UserInputService/InputBegan User#20388 0 — 5y

Answer this question