Why this OnServerEvent paramenters aren't exactly how in FireServer()?
Asked by
4 years ago Edited 4 years ago
Hello, devs!
Title might be hard to understand, but I'll try to make you understand my problem. So I was trying to animate First Person Shooter and made script that will fire server into RemoteEvent when left mouse button pressed and then script will collect it by OnServerEvent but parameters send by FireServer(parameters) aren't same as OnServerEvent(parameters). I used player before using my parameter. There is no errors on output. Thanks in advice.
CODE:
Local Script
1 | local player = game.Players.LocalPlayer |
3 | local mouse = player:GetMouse() |
5 | mouse.Button 1 Down:Connect( function () |
6 | game.ReplicatedStorage.Shot:FireServer(player, workspace.Camera) |
Script
1 | local anim = script.ShotAnim |
3 | game.ReplicatedStorage.Shot.OnServerEvent:Connect( function (player, cam) |
4 | print (cam.Name .. " " .. player.Name) |
5 | local human = cam:WaitForChild( "Arms" ):FindFirstChild( "Humanoid" ) |
6 | local shot = human:LoadAnimation(anim) |
OUTPUT:
No errors
MyUsername MyUsername
DETAILS
Local Script located in StarterCharacterScripts and sends signal, Script located in workspace and collects signal, but something is wrong with parameters.
EDIT:
I removed player in parameters of FireServer() but then it prints out:
Workspace.ShotEvent:4: attempt to index nil with 'Name'
EDIT2:
I edited script to:
01 | local anim = script.ShotAnim |
03 | game.ReplicatedStorage.Shot.OnServerEvent:Connect( function (player, cam) |
05 | local human = cam:WaitForChild( "Arms" ):FindFirstChild( "Humanoid" ) |
06 | local shot = human:LoadAnimation(anim) |
09 | print ( "Doesn't work." ) |
It prints out "Doesn't work." on output.
EDIT3:
I edited script to:
local anim = script.ShotAnim
1 | game.ReplicatedStorage.Shot.OnServerEvent:Connect( function (player, cam) |
3 | local human = cam:WaitForChild( "Arms" ):FindFirstChild( "Humanoid" ) |
4 | local shot = human:LoadAnimation(anim) |
EDIT3 OUTPUT:
nil
Workspace.ShotEvent:5: attempt to index nil with 'WaitForChild'