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

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

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

✓ Accepted answer

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)

2 comments

0

Thanks this really helped!

0

Glad I could help.

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