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 3 years ago
Edited 3 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

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    game.ReplicatedStorage.Shot:FireServer(player, workspace.Camera)
end)

Script

local anim = script.ShotAnim

game.ReplicatedStorage.Shot.OnServerEvent:Connect(function(player, cam)
    print(cam.Name .." ".. player.Name)
    local human = cam:WaitForChild("Arms"):FindFirstChild("Humanoid")
    local shot = human:LoadAnimation(anim)
    shot:Play()
end)

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:

local anim = script.ShotAnim

game.ReplicatedStorage.Shot.OnServerEvent:Connect(function(player, cam)
    if cam then
        local human = cam:WaitForChild("Arms"):FindFirstChild("Humanoid")
        local shot = human:LoadAnimation(anim)
        shot:Play()
    else
        print("Doesn't work.")
    end
end)

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

EDIT3:

I edited script to:

local anim = script.ShotAnim

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

EDIT3 OUTPUT:

nil

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

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 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 — 3y
0
Don't work... ErktikyYT 89 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

Server Script

local anim = script.ShotAnim
local cam = workspace.Camera
game.ReplicatedStorage.Shot.OnServerEvent:Connect(function(player)
print(workspace.Camera.Name .." ".. player.Name)
local human = cam:WaitForChild("Arms"):FindFirstChild("Humanoid")
local shot = human:LoadAnimation(anim)
shot:Play()
end)

Client Script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
game.ReplicatedStorage.Shot:FireServer()
end)
0
I'll try, but I don't this this is gonna work because I think that camera is client item. ErktikyYT 89 — 3y
0
What about playing animation tho? ErktikyYT 89 — 3y
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 — 3y
0
hm thats odd it did with me Harry_TheKing1 325 — 3y

Answer this question