Help With Cloning a Gui

I have a script that reads all keys of a data store, and then it creates a new GUI for each key. I think the part that reads the data store is good, but it still won’t show the newly created GUIs, so I’m 99% sure that it’s a problem with the GUI creating script. I’ll put both scripts here just in case.

Server side DataStore reading script:

local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local addGui = ReplicatedStorage.FireAddGUI

local DataStoreService = game:GetService("DataStoreService")
local rankedStore = DataStoreService:GetDataStore("RankedStore")

Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(11635716) >= 254 then
		local pages = rankedStore:ListKeysAsync()
		
		local passed = {}
		
		while task.wait(0.1) do		
			for i, v in ipairs(pages:GetCurrentPage()) do
				table.insert(passed,v)
			end
			
			if pages.IsFinished == true then
				break
			end
			
			pages:AdvanceToNextPageAsync()
		end	
		
		for i, name in pairs(passed) do
			addGui:FireClient(plr,name.KeyName)
			print("ui request sent")
		end
	end
end)

Client side GUI creator script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fireAddGui = ReplicatedStorage.FireAddGUI

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local resultsScreen = playerGui:WaitForChild("ResultsScreen")
local resultsFrame = resultsScreen.ScrollingFrame
local playerEx = resultsFrame.PlayerExample

local xValue = playerEx.Position.X.Offset
local yValue = playerEx.Position.Y.Offset

fireAddGui.OnClientEvent:Connect(function(plr,name)
	if plr == localPlayer then
		local player = playerEx:Clone()
		player.Visible = true
		player.Name = "Player"
		player.Position.X.Offset = tonumber(xValue)
		player.Position.Y.Offset = tonumber(yValue) - 10
		player.Text = name.Name
		print("ui added")
	end
end)

The output window does print “ui request sent”, but not “ui added”. This is mostly why I think it is a problem with the second script. How can I fix this?

Not that strong with scripts but dont you need to parent the clone?

It didn’t work. I think the problem could be with the way I’m changing the location of the GUI on the screen, but I don’t know how to fix it.

1 Like

Use UDim2.new(0,xValue,0,yValue).

The position is set on one line like this for offset.

1 Like

See quite a few wrong things:

  • There’s no need for
if plr == localplayer then

because when you FireClient(player) only that player will be affected. That’s literally why FireClient() exists, if you were to do FireAllClients() then you could check for stuff like that.

  • When changing a position of anything you can’t change the axis individually like that, instead you have to create a new position like this,
player.Position = UDim2.new(0, tonumber(xValue), 0, tonumber(yValue) - 10)
1 Like

Did you parent it to the PlayerGui?

At the end parent it
If it’s a whole seperate GUI

player.Parent = plr.StarterGui -- OR playergui but I think that's only for server scripts

if it’s like a frame or such

player.Parent = Gui -- Change Gui to the Gui the frame should be in

Also you should probably clone this on the server instead

StartGui turns to PlayerGui when the game begins, so its always PlayerGui when parenting through script.

Also PlayerGui’s are handled through local scripts.

1 Like

That worked, but now it’s changing the text to nil, not 62penguins, which should be in the data store. Would it not work because It’s studio?

Maybe, make sure that API services are on if you wanna test in roblox studio anything related to data

1 Like

Yes, the API services are on in my game settings, and I saved it.