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

I'm having problems with sending variables trough a RemoteEvent. How can I fix this problem?

Asked by 4 years ago

I'm trying to make a throwable bomb but when I send a variable trough a RemoteEvent it returns as nil

-- Local script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    game.ReplicatedStorage.Events.BombEvent:FireServer(mouse)
end)


-- Server script: game.ReplicatedStorage.Events.BombEvent.OnServerEvent:Connect(function(plr, mouse) print(mouse.Target) -- The mouse variable returns as nil end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You cannot pass the mouse object from the client to the server, it will result in nil because the server cannot see the mouse object in the first place.

You could just send the mouse.Target from the client to the server instead so it would look kinda like this

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    game.ReplicatedStorage.Events.BombEvent:FireServer(mouse.Target)
end)

And the server would look like

game.ReplicatedStorage.Events.BombEvent.OnServerEvent:Connect(function(plr, mouse)
    if mouse then
        print(mouse.Name) --//This means that the mouse.Target we sent on the client did in fact exist
    end
end)
0
Thanks this really helped! iFrexsim 0 — 4y
0
Glad I could help. CeramicTile 847 — 4y
Ad

Answer this question