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

RemoteEvent does not want to work properly, giving an error?

Hi, I'm making a pick-up system but it doesn't work. There will be an error.

Client script:

local Player = game:GetService("Players").LocalPlayer

local Mouse = Player:GetMouse()

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("LootPickup")

Mouse.Button1Down:Connect(function()
	
	RemoteEvent:FireServer(Player, Mouse)
end)

Server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("LootPickup")

RemoteEvent.OnServerEvent:Connect(function(Player, Mouse)
	
	if Player then
		
		local Target = Mouse.Target
		
		if Target:FindFirstChild("Loot") then
			
			Target:Destroy()
			
			print("Succesfully picked up loot.")
		end
	end
end)

Error: Target is not a valid member of Player, line 11 in the Server script.

2 comments

1

You can't pass mouse to the server, also the player is an argument of OnServerEvent by default

0

Thanks, worked.

1 answer

At the client instead of Player, Mouse does just Mouse because it thinks that the mouse is inside player, If you know much about remote events at onserverevent you always gotta put Player already!

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