Problem with client event

local miningevent = game:GetService("ReplicatedStorage"):WaitForChild("Mining")
local oreevent = game:GetService("ReplicatedStorage"):WaitForChild("GetOre")
local hv = script.Parent
local pickaxestrength = 1

miningevent.OnServerEvent:Connect(function()
	if not hv then return end -- stop code if hv got destroyed
	hv.Value -= pickaxestrength
	oreevent:FireClient()
	print(hv.Value)
end)

hv:GetPropertyChangedSignal("Value"):Connect(function()
	if hv.Value == 0 or hv.Value<0 then
		print("destroyed")
		script.Parent.Parent:Destroy()
	end
end)

image
there is an error about the client event, it says that an argument is missing but i can’t understand what’s missing, the event is used for another script:

local sss = script.Parent
local pd = sss.PlayerData
local data = pd.Data
local manager = require(pd.Manager)
local rs = game:GetService("ReplicatedStorage")
local oreevent = rs.GetOre
local oremultiplier = math.random(1.1, 2)
local pickstrength = require(pd.Pickaxe)
local wpick = pickstrength.woodpick

local function addore(player: Player)
	manager.AdjustOres(player, wpick*oremultiplier)
end

oreevent.OnClientEvent:Connect(addore)

Anyone can help?..

1 Like

When using FireClient you need a player to fire the remote to, you can get the player who fired it in OnServerEvent by using
OnServerEvent:Connect(function(plr)
and use FireClient(player) to fire it to the player

1 Like

Server Script

local miningevent = game:GetService("ReplicatedStorage"):WaitForChild("Mining")
local oreevent = game:GetService("ReplicatedStorage"):WaitForChild("GetOre")
local hv = script.Parent
local pickaxestrength = 1

miningevent.OnServerEvent:Connect(function(player)
	if not hv then return end -- stop code if hv got destroyed
	hv.Value -= pickaxestrength
	oreevent:FireClient(player)
	print(hv.Value)
end)

hv:GetPropertyChangedSignal("Value"):Connect(function()
	if hv.Value == 0 or hv.Value<0 then
		print("destroyed")
		script.Parent.Parent:Destroy()
	end
end)

Client Script

local player = game.Players.LocalPlayer
local sss = script.Parent
local pd = sss.PlayerData
local data = pd.Data
local manager = require(pd.Manager)
local rs = game:GetService("ReplicatedStorage")
local oreevent = rs.GetOre
local oremultiplier = math.random(1.1, 2)
local pickstrength = require(pd.Pickaxe)
local wpick = pickstrength.woodpick

local function addore()
	manager.AdjustOres(player, wpick*oremultiplier)
end

oreevent.OnClientEvent:Connect(addore)

The remote event still wont fire
image

local player = game.Players.LocalPlayer
local sss = script.Parent
local pd = sss.PlayerData
local data = pd.Data
local manager = require(pd.Manager)
local rs = game:GetService("ReplicatedStorage")
local oreevent = rs.GetOre
local oremultiplier = math.random(1.1, 2)
local pickstrength = require(pd.Pickaxe)
local wpick = pickstrength.woodpick

local function addore()
	print("fired	")
	manager.AdjustOres(player, wpick*oremultiplier)
end

oreevent.OnClientEvent:Connect(addore)

It might be because the addOre function does not take any arguments. Try using:
local function addore(player)

on second thought, nvm

The OnClientEvent event has no default player argument, unlike OnServerEvent

I had a similar issue before and local function addore(player) did indeed fix it for me. You should definitely consider trying that out. :slight_smile:

How exactly did it fix the issue? local function addore(player)? The function is called by OnClientEvent and there will be no parameters when calling the function

Where exactly are you firing to the server?

Also: What is script.Parent?

it’s server script service ( sorry i forgot to rename it )

yes i tried that out but…
image
image
still nothing.

you cant do .OnClientEvent on the Server

but for some reason everytime i put the local script anywhere else, there’s another error:
image
image
but its clearly there.
image

Yes because the LocalScript can’t access the ServerStorage + ServerScriptService, its meant for server-scripts only

oh…
i didn’t know that, sorry

1 Like

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