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 3 years ago
Edited 3 years ago

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.

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

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 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