I encountered a problem in my script when i was checking if a player was holding down the Q key have no idea how i can fix this.
Here are my two scripts :
The Client script
local UserInputService = game:GetService("UserInputService") local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local character = player.Character or player.CharacterAdded:Wait() local block = game.Workspace.Part:Clone() block.Parent = workspace local Key = 'Q' local debounce = true UserInputService.InputBegan:Connect(function(Input ,IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if Input.UserInputType == Enum.UserInputType.Keyboard then if KeyPressed == Enum.KeyCode[Key]and debounce and character then game.ReplicatedStorage.FireBallEvent:FireServer(Mouse.Hit, UserInputService, Key) end end end)
The Server Script
local fireball = Instance.new("Part", workspace) game.ReplicatedStorage.FireBallEvent.OnServerEvent:Connect(function(player, mouse, UserInputService, Key) while wait(1) do if UserInputService:IsKeyDown(Enum.KeyCode[Key]) then print("the fireball is being charged!") fireball.Size = fireball.Size + Vector3.new(0.01,0.01,0.01) else print("the fireball has been fired!") break; end end end)
UserInputService is client-sided; if you need to know if a client has a specific key down, you could use a remote function.
You cannot transmit Services though RemoteEvents. Instead just make an event inside of the player with Instance.new and just make the fireball creation part the remotevent.