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

server events are not working variables are not getting through?

Asked by 3 years ago

so this is from the receiving side in a script in starter character scripts:

game.ReplicatedStorage.jump.OnServerEvent:Connect(function(me, mouse)
    mouse.KeyUp:Connect(function(key)
        if key == "Space" then
            holding = false
        end
    end)
end)

and this is the sending side in a local script also in starter character scripts:

local mouse = game.Players.LocalPlayer:GetMouse()
game.ReplicatedStorage.jump:FireServer(mouse)

and there is a remote event named jump in replecated storage when i print mouse on local script it says instance (good) but when i print mouse in script it says nil (bad) why is this happening?

0
https://scriptinghelpers.org/guides/server-client-relationship-in-roblox. Please try to understand basic networking before attempting to build a Client-to-Server relationship. You shouldn't be trying to use Client-orientated Instances on the Server, it is meant to operate in LocalScripts only. You can simply detect the key state of the spacebar and send the boolean instead. Ziffixture 6913 — 3y
0
You're also using an outdated form of keyboard-input recognition, it was superseded by UserInputService several years ago. Ziffixture 6913 — 3y
0
Loading... botw_legend 502 — 3y
0
Loading... botw_legend 502 — 3y

1 answer

Log in to vote
1
Answered by
blazar04 281 Moderation Voter
3 years ago

The API for GetMouse() states: "This item must be used in a LocalScript to work as expected online."

I think you would be better off using UserInputService on the client (LocalScript) to get the player's input, and then fire the remote event. Something like this:

local UserInputService = game:GetService("UserInputService")
local remoteEvent = game:GetService("ReplicatedStorage").jump

UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Space then
        jump:FireServer()
    end
end)

I recommend you read the documentation on UserInputService if you don't fully understand.

Hope this helped, good luck!

Ad

Answer this question