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

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

1local player = game.Players.LocalPlayer
2 
3local mouse = player:GetMouse()
4 
5mouse.Button1Down:Connect(function()
6    game.ReplicatedStorage.Shot:FireServer(player, workspace.Camera)
7end)

Script

1local anim = script.ShotAnim
2 
3game.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)
7    shot:Play()
8end)

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:

01local anim = script.ShotAnim
02 
03game.ReplicatedStorage.Shot.OnServerEvent:Connect(function(player, cam)
04    if cam then
05        local human = cam:WaitForChild("Arms"):FindFirstChild("Humanoid")
06        local shot = human:LoadAnimation(anim)
07        shot:Play()
08    else
09        print("Doesn't work.")
10    end
11end)

It prints out "Doesn't work." on output.

EDIT3:

I edited script to:

local anim = script.ShotAnim

1game.ReplicatedStorage.Shot.OnServerEvent:Connect(function(player, cam)
2    print(cam)
3    local human = cam:WaitForChild("Arms"):FindFirstChild("Humanoid")
4    local shot = human:LoadAnimation(anim)
5    shot:Play()
6    print("Doesn't work.")
7end)

EDIT3 OUTPUT:

nil

Workspace.ShotEvent:5: attempt to index nil with 'WaitForChild'

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You don't need to put "player" as a parameter in a local script, just in the server script. Not sure about the error though.

maybe try doing game.Workspace.Camera and if that doesn't work try doing game.Workspace.CurrentCamera.

0
I'll try. ErktikyYT 89 — 4y
0
Don't work... ErktikyYT 89 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Im Not Sure If Clients Can Send Client Items But You Can Try This:

Server Script

1local anim = script.ShotAnim
2local cam = workspace.Camera
3game.ReplicatedStorage.Shot.OnServerEvent:Connect(function(player)
4print(workspace.Camera.Name .." ".. player.Name)
5local human = cam:WaitForChild("Arms"):FindFirstChild("Humanoid")
6local shot = human:LoadAnimation(anim)
7shot:Play()
8end)

Client Script

1local player = game.Players.LocalPlayer
2local mouse = player:GetMouse()
3mouse.Button1Down:Connect(function()
4game.ReplicatedStorage.Shot:FireServer()
5end)
0
I'll try, but I don't this this is gonna work because I think that camera is client item. ErktikyYT 89 — 4y
0
What about playing animation tho? ErktikyYT 89 — 4y
0
I added local human = workspace.Camera:WaitForChild("Arms"):FindFirstChild("Humanoid") and print(human.Parent.Name) but it didn't printed anything so workspace.Camera don't work for my anim playing. ErktikyYT 89 — 4y
0
hm thats odd it did with me Harry_TheKing1 325 — 4y

Answer this question