Remote Events Help

okay so i have this script that uses Number Values under a rock in workspace, Durability and Worth, i have this local script:

local tool = script.Parent
local range = 20
local hit = game.ReplicatedStorage.MiningRemotes.Hit

local function onActivated()
	local mouse = game.Players.LocalPlayer:GetMouse()
	local mouseTarget = mouse.Target

	local playerPosition = game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.HumanoidRootPart.Position
	local targetPosition = mouseTarget and mouseTarget.Position

	if mouseTarget and mouseTarget.Name == "Rock" and playerPosition and targetPosition and (playerPosition - targetPosition).Magnitude <= range then
		local dur = mouseTarget.Durability.Value
		local mon = mouseTarget.Worth.Value
		hit:FireServer(dur, mon)
	end
end

tool.Activated:Connect(onActivated)

and a server script:

local remote = game.ReplicatedStorage.MiningRemotes.Hit

remote.OnServerEvent:Connect(function(dur, mon)
	print(mon)
	print(dur)
end)

the durability prints fine (2) but the worth value does this:

1 Like

OnServerEvents automatically take the player as the first argument, which means that dur is the player, mon is dur, and the actual mon is nil. Try replacing that line with instead:

remote.OnServerEvent:Connect(function(plr, dur, mon)

You can also see that in the prints, you printed mon first (which is dur’s value, 2) and dur (which is the player), somehow it does that

1 Like

when OnServerEvent is called the first arguement is the player so its just printing the player (dur is the player value)

a correct use would look like this on the server end

remote.OnServerEvent:Connect(function(player, dur, mon)
	print(mon)
	print(dur)
end)
1 Like

i updated the code and it still prints the same

1 Like

server script

local remote = game.ReplicatedStorage.MiningRemotes.Hit

remote.OnServerEvent:Connect(function(plr, dur, mon)
	print(mon)
	print(dur)
end)

local script:

local tool = script.Parent
local range = 20
local hit = game.ReplicatedStorage.MiningRemotes.Hit
local plr = game.Players.LocalPlayer

local function onActivated()
	local mouse = game.Players.LocalPlayer:GetMouse()
	local mouseTarget = mouse.Target

	local playerPosition = game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.HumanoidRootPart.Position
	local targetPosition = mouseTarget and mouseTarget.Position

	if mouseTarget and mouseTarget.Name == "Rock" and playerPosition and targetPosition and (playerPosition - targetPosition).Magnitude <= range then
		local dur = mouseTarget.Durability.Value
		local mon = mouseTarget.Worth.Value
		hit:FireServer(plr, dur, mon)
	end
end

tool.Activated:Connect(onActivated)

1 Like

i also tried

local dur = mouseTarget:FindFirstChild(Durability).Value

local mon = mouseTarget:FindFirstChild(Worth).Value

still doesnt work

1 Like

You only need the player for OnServerEvent, not FireServer. If you aren’t sure about RemoteEvents then check out the documentation
If the problem still persists then it might come from another script

i figured it out! thank you very much

1 Like

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