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

How do I carry a variable through a remote event?

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

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)

1 comment

0

Check it as Answear

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