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'
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.
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)