Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

server events are not working variables are not getting through?

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?

4 comments

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.

0

You're also using an outdated form of keyboard-input recognition, it was superseded by UserInputService several years ago.

0

Loading...

0

Loading...

1 answer

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.