Help With Trading System

  1. What do you want to achieve?
    Trade System | Show GUI on the server


I want a item GUI show on the trade GUI for both trader

  1. What is the issue? Include screenshots / videos if possible!
    I tried to send GUI to the server via Remote Event but ended up gives nil

Erorr:
ServerScriptService.TradeHandler:52: attempt to index nil with 'Parent'

  1. What solutions have you tried so far?
    Tried searching on devforum and google but no results. I don’t wanna try to search on yt because I wanna make it by myself without using yt. Just wanna practice my knowledge

I also tried to use MouseButton1Click on the server, but still NIL
Trade Local Script:

    local MenuTrade = script.Parent.MenuTrade
local TradeGUI = script.Parent.TradeGUI
local ItemsListGUI  = script.Parent.TradeGUI.Items.ListItems
local Trade1 = TradeGUI.Trade1
local Trade2 = TradeGUI.Trade2
local CancelButton = TradeGUI.CancelButton
local TradeButton = TradeGUI.TradeButton
local Notification = MenuTrade.Parent.NotificationTrade
local localPlayer = game.Players.LocalPlayer
local OwnedTrails = game.Players.LocalPlayer:WaitForChild("OwnedTrails")
local OwnedSwords = game.Players.LocalPlayer:WaitForChild("OwnedSwords")
local ItemsTrade = localPlayer:WaitForChild("ItemsTrade")

local function PlayerTradeGUI()
	print("Joined")
	for _, player in pairs(game.Players:GetPlayers()) do

		local pagePlayer = script.Pages:Clone()

		pagePlayer.Player.Text = player.Name
		pagePlayer.Parent = MenuTrade.ListPlayers

		pagePlayer.TradeButton.MouseButton1Click:Connect(function()
			
			game.ReplicatedStorage.TradeRE.SendMesssageRE:FireServer(pagePlayer.Player.Text)
		end)
	end
end


for _, trail in pairs(OwnedTrails:GetChildren()) do
	local itemForTrade = trail:Clone()
	
	itemForTrade.Name = trail.Name
	itemForTrade.Parent = ItemsTrade
end

for _, Swords in pairs(OwnedSwords:GetChildren()) do
	local itemForTrade = Swords:Clone()

	itemForTrade.Parent = ItemsTrade
	itemForTrade.Name = Swords.Name
end

for _, items in pairs(ItemsTrade:GetChildren()) do
	local ItemSword = script.ItemSword:Clone()
	local ItemTrail = script.ItemTrail:Clone()
	
	if items:IsA("Trail") then
		ItemTrail.Trail.UIGradient.Color = items.Color
		ItemTrail.Name = items.Name
		ItemTrail.Parent = ItemsListGUI
		ItemTrail.TrailName.Text = items.Name
	end
	
	if items:IsA("Tool") then
		ItemSword.Name = items.Name
		ItemSword.SwordName.Text = items.Name
		ItemSword.ImageLabel.Image = items.TextureId
		ItemSword.Parent = ItemsListGUI
	end
		
	for _, itemsInList in pairs(ItemsListGUI:GetChildren()) do
		if itemsInList:IsA("TextButton") then
			itemsInList.MouseButton1Click:Connect(function()
				local SendItem = itemsInList:Clone()
				game.ReplicatedStorage.TradeRE.SendItemRE:FireServer(items, SendItem)
			end)
		end
	end
end

PlayerTradeGUI()

Trade Server Script:

game.Players.PlayerAdded:Connect(function(player)
	local IsInTrade = Instance.new("BoolValue")
	IsInTrade.Parent = player
	IsInTrade.Name = "IsInTrade"
	IsInTrade.Value = false
	
	local IsRequesting = Instance.new("BoolValue")
	IsRequesting.Parent = player
	IsRequesting.Name = "IsRequesting"
	IsRequesting.Value = false
	
	local ItemsTrade = Instance.new("Folder")
	ItemsTrade.Parent = player
	ItemsTrade.Name = "ItemsTrade"
	
end)


game.ReplicatedStorage.TradeRE.SendMesssageRE.OnServerEvent:Connect(function(plr, PlayerRequested)
	local PlayerReceive = game.Players:WaitForChild(PlayerRequested)
	local PlayerReceiveGUI = PlayerReceive:WaitForChild("PlayerGui"):WaitForChild("TradeScreen")
	local plrGUI = plr:WaitForChild("PlayerGui"):WaitForChild("TradeScreen")
	
	local plrValue = plr.IsRequesting
	local plrReceiveValue = PlayerReceive.IsRequesting
	
	PlayerReceiveGUI.NotificationTrade.Visible = true
	plrReceiveValue.Value = true
	plrValue.Value = true
	
	PlayerReceiveGUI.NotificationTrade.Accept.MouseButton1Click:Connect(function()
		plrReceiveValue.Value = false
		plrValue.Value = false
		
		plrGUI.TradeGUI.Visible = true
		PlayerReceiveGUI.TradeGUI.Visible = true
		plrGUI.MenuTrade.Visible = false
		PlayerReceiveGUI.MenuTrade.Visible = false
		PlayerReceiveGUI.NotificationTrade.Visible = false
		plrGUI.NotificationTrade.Visible = false
	end)
	
	game.ReplicatedStorage.TradeRE.SendItemRE.OnServerEvent:Connect(function(player, itemSend, ItemGUI)
		local ItemsToBeSent = {}
		
		print("Give")
		print(ItemGUI)
		local itemForReceive = ItemGUI
		local ItemForGive = ItemGUI
		print(ItemForGive)
		print(itemForReceive)
		itemForReceive.Parent = PlayerReceiveGUI.TradeGUI.Trade2
		ItemForGive.Parent = plrGUI.TradeGUI.Trade1
		
		
	end)
	
end)
2 Likes

MouseButton1Click not run the server script.

1 Like

Bumping up this post.

So just managed to fix this bug. What I did is just do the guis on the server side. If i would just do client - server method, the server won’t detect gui inside the player since the guis are made on client side.