Why Dosen't This ServerEvent Fire?

I need my server event to be fired when the key is pressed, the issue probably has something to do with the FireServer line itself because everything I had a “print” for outputed fine locally. However the event im firing itself dosent print anything (you will see what im talking about in the script) I tried making the player variable 1st but that didn’t do anything.

local Script

UserInputService.InputBegan:Connect(function(input, event)
	if input.KeyCode == Enum.KeyCode.E then
		print("E Pressed")
		local PunchPower = Power - 17
		local Animation = script.Parent.Animations.P1
		ReplicatedStorage.FightingEvents.Punch:FireServer(player, Stamina, Speed, PunchPower, Hand, Animation)
		print("FiredServerFromClient")
	end
end)

ServerScript

ReplicatedStorage.FightingEvents.Punch.OnServerEvent:Connect(function(player, Stamina, Speed, Power, Hand, Animation)
	print("EventFired")

Everything you see listed here prints fine excpet for the print for the server script. Which probably means that the FireServer event had some kind of issue.

2 Likes

Everything provided works fine, provided that all the variables you have are correctly set.
So here’s what you should look into to try and resolve the problem.

  • If both ‘E Pressed’ and ‘FiredServerFromClient’ are printed, then this issue is likely occurring server-side because that there is no error in the code block firing the event. So write a print statement right before you connect the event.
    • If that statement doesn’t print, your code’s control flow never gets to that point in the script and never connects the event. So it’s an error occurring earlier in the server script.
  • If only ‘E Pressed’ is printed, then there’s an issue in the client-code.

Few other details to note, when an event is fired, the first argument passed is always the player firing. So you don’t need to include your player variable as a parameter.
UserInputService fires at all conveniences of user input, even when the player types in chat. So you might find it useful to check if Event is true (the parameter passed in states whether the event has already been processed by the game).

2 Likes

Where is the end? That might be your problem.

Also, as a sidenote, avoid using UserInputService for input. Instead, use ContextActionService, as it automatically creates buttons for mobile and binds multiple possible inputs to one function.

1 Like

Your code seems correct the only error I see is when your calling fire server from the client there is no need to pass the player argument, as it is automatically sent over so this should be your line:

ReplicatedStorage:WaitForChild("FightingEvents"):WaitForChild("Punch"):FireServer(Stamina, Speed, PunchPower, Hand, Animation)

Also, if your calling from the client I think you need to add a WaitForChild when loading the event

1 Like

Make sure the ReplicatedStorage variable in your script is set to

game:GetService("ReplicatedStorage")

game.ReplicatedStorage would also work that does not matter

1 Like

It does matter, as if it’s set to something else then the server wouldn’t know if it was fired.
Also, GetService is more dependable https://devforum.roblox.com/t/use-of-getservice/204362/2?u=gamerobotjimmy

It’s a preference, but since it’s a service call it’s better to use game:GetService(“SERVICE”) rather than treating it as a child of the game. Plus it takes care if you rename any service inside of the workspace as @gamerobotjimmy has mentionsed.

1 Like

Actually GetService is a more secure way to be sure that the service you are trying to get will be there and you will be able to interact with it

So there are 3 things i’ve noticed.
1- You are passing a player argument to the server, it automatically does that so you can remove the player in the :FireServer() and keep the OnServerEvent player

2- There is no end) in the OnServerEvent

3- I dont know if you made a variable for that or not but the ReplicatedStorage needs to be game.ReplicatedStorage or can be game:GetService(“ReplicatedStorage”)