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)
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.
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).
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.
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:
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.
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”)