Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago

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

Client script:

01local Player = game:GetService("Players").LocalPlayer
02 
03local Mouse = Player:GetMouse()
04 
05local ReplicatedStorage = game:GetService("ReplicatedStorage")
06 
07local RemoteEvent = ReplicatedStorage:WaitForChild("LootPickup")
08 
09Mouse.Button1Down:Connect(function()
10 
11    RemoteEvent:FireServer(Player, Mouse)
12end)

Server script:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02 
03local RemoteEvent = ReplicatedStorage:WaitForChild("LootPickup")
04 
05RemoteEvent.OnServerEvent:Connect(function(Player, Mouse)
06 
07    if Player then
08 
09        local Target = Mouse.Target
10 
11        if Target:FindFirstChild("Loot") then
12 
13            Target:Destroy()
14 
15            print("Succesfully picked up loot.")
16        end
17    end
18end)

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

1
You can't pass mouse to the server, also the player is an argument of OnServerEvent by default Amiaa16 3227 — 4y
0
Thanks, worked. Bankrovers 226 — 4y

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
4 years ago

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!

Ad

Answer this question