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

How do I make a variable cross over using a RemoteEvent?

I'm making a sell to player gui and I have this as a local script under StarterPlayerScripts

local Player = game.Players.LocalPlayer -- Getting the player   
local Mouse = Player:GetMouse() -- Getting the players mouse


Mouse.Button1Down:Connect(function() -- Detecting when player presses the left mouse button
    if Mouse.Target.Parent:FindFirstChild("Humanoid") and 
        game.Players.LocalPlayer.TeamColor.Name == ("Dirt brown") then -- Checking if the Mouse is over a player
        print(Mouse.Target.Parent.Name) 
		game.ReplicatedStorage.SellPistol:FireServer(Mouse.Target)
		
	


    end
end)

I also have this being connected to in a script under ServerScriptService

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(Mouse.Target)
	Mouse.Target.StarterGui.StartScreen.Frame = Visible
end






SellPistol.OnServerEvent:Connect(onSellPistol)

How can I bring the (Mouse.Target) into the script using the FireServer from the RemoteEvent?

1 comment

0

You can simply pass it as a parameter as you would to anything else.

1 answer

✓ Accepted answer

The receiving script always has to have the first argument as the player, also I suggest not using dots. A fixed version of your second script:

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(player, mousetarget)
    mousetarget.StarterGui.StartScreen.Frame = Visible
end






SellPistol.OnServerEvent:Connect(onSellPistol)

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