Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why this OnServerEvent paramenters aren't exactly how in FireServer()?

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

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.

2 comments

0

I'll try.

0

Don't work...

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)

4 comments

0

I'll try, but I don't this this is gonna work because I think that camera is client item.

0

What about playing animation tho?

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.

0

hm thats odd it did with me

This discussion is preserved as it was. New answers, comments, and votes are closed.