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

ServerScriptService.Script:3: attempt to index nil with 'IsKeyDown' ?

Asked by
Dec_ade 47
4 years ago
Edited 4 years ago

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)
1
Why are you using UserInputService on the server? User#5423 17 — 4y
0
you cant use Heavenlyblobmaster 271 — 4y
0
user imput service Heavenlyblobmaster 271 — 4y
0
on the server side Heavenlyblobmaster 271 — 4y
0
Because I want others players to see the fireball changing its size. Dec_ade 47 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

UserInputService is client-sided; if you need to know if a client has a specific key down, you could use a remote function.

Ad
Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago

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.

Answer this question