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

How do I carry a variable through a remote event?

Asked by 2 years ago

The variable I am talking about is called "object" The problem with it is that the variable is only able to be defined in the local script.

Here is the code for the local script:

local player = game.Players.LocalPlayer
local BPK = player:WaitForChild("BPK")
local object = BPK:FindFirstChild(script.Parent.Parent)
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.ChangeInfoGui:FireServer(object)
end)

Here is the code from the server script:

game.ReplicatedStorage.ChangeInfoGui.OnServerEvent:Connect(function(player, object)
    local info = player.PlayerGui.Back.Info
    local BPK = player:WaitForChild("BPK")

    info.Transparency = 0
    info.ObjDesc.Transparency = 0
    info.ObjName.Transparency = 0

    info.ObjName.Text = object.Name
    info.ObjDesc.Text = object.Description.Value
end)

1 answer

Log in to vote
0
Answered by 2 years ago

I was doing it correctly I just changed the code to this (on the local script):

local player = game.Players.LocalPlayer
local BPK = player:WaitForChild("BPK")
local name = script.Parent.Parent.Name
local object = BPK:FindFirstChild(name)
print(object)
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.ChangeInfoGui:FireServer(object)
end)
0
Check it as Answear DefinitelyNotTronix 19 — 2y
Ad

Answer this question