Argument 1 missing or nil

Have this script where it plays a sound from your tool when you do a certain action, the LocalScript is in the tool, whereas the server script is in ServerScriptService.

It works for when you equip the tool, but when :FireServer() is called again from the client with another action, it errors.

Works:

tool.Equipped:Connect(function()
	rs.ToolSound:FireServer("Equip", tool.Name)
end)

Does not work:

tool.Activated:Connect(function()
	rs.ToolSound:FireServer("Fire")
end)

The server script:

local rs = game:GetService("ReplicatedStorage")

rs.ToolSound.OnServerEvent:Connect(function(plr, soundtype, toolname)
	plr.Character:FindFirstChild(toolname).Handle:FindFirstChild(soundtype):Play()
	print(soundtype)
end)

Not sure what’s wrong, i’ve checked plr, soundtype, and toolname and neither come out as nil.

tool.Activated:Connect(function()
rs.ToolSound:FireServer(“Fire”,tool.Name)
end)

1 Like

u didnt send the 2nd parameter in tool.Activated

2 Likes

Well now I just feel dumb, guess that’s what exhaustion does to you.

1 Like

i suggest taking a rest if u feel tired because tiresome can make you code worse

On top of this, you can pass instances through RemoteEvents if the instance is replicated between server and client, so you can just pass the tool itself (or the sound itself, even), instead of its name:
Client:

rs.ToolSound:FireServer("Equip", tool)

Server:

rs.ToolSound.OnServerEvent:Connect(function(plr, soundtype, tool)
	tool.Handle:FindFirstChild(soundtype):Play()
	print(soundtype)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.