How do i identify frames cloned locally in a server/global script?

Well, one of the issues of my shop is that when i send a remove event to find the frame in a global script, the script cannot find the frame, error printing that the frame is nil. Well, here is the script if you need it, maybe you don’t need it, but it’s a local script:

Script
local Lighting = game:GetService("Lighting")
local ShopItems = Lighting.Pets
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopData = require(ReplicatedStorage.ShopData)
local PetsData = ShopData["Pets"]

local PrefabItem = ReplicatedStorage.ShopStuff:FindFirstChild("SlotLayout")

local Frame = script.Parent.PetsFrame

for _, Pet in pairs(ShopItems:GetChildren()) do
  local Item = PrefabItem:Clone()
    if (PetsData[Pet.Name]) then --//CHANGED LINE
        local PetData = (PetsData[Pet.Name]) --//CHANGED LINE
        Item.Parent = Frame
        Item.Name = Pet.Name
        Item.Info.Text = PetData["Info"]
        Item.Cost.Value = PetData["Cost"]
        Item.ImageShow.Image = "rbxassetid://" .. PetData["ImageId"]
	wait(0.2)
	end
end

Well, i want to know, how can i find the frame in any global script. I hope you respond me :+1: And this is very important to me :slight_smile:.

1 Like

Anything UI related should be handled locally. The only client-server interaction should be when the player decides to buy something, in which case an event is sent for the server to handle the transaction.

Yeah, but the problem is that the server script is not identifying the cloned frames. I don’t know if that is caused by the local script. As i have read, most of the stuff made by local script can only be actived/seen by the player, but i dont know how to make that visible by also the server.

If workspace.FilteringEnabled is enabled (which it should be, don’t touch it) then instances created on the client (localscript) will not be visible to the server (regular/‘global’ script).

If for whatever reason you really, really need a players UI to be visible to the server then you have to create those objects in PlayerGui from a server script, which will then be replicated to the player.

But you should take @Blokav’s advice.

1 Like

I already tried that before posting this thread, but that didn’t worked, since the ScreenGui was nil for the Server, ScreenGui is not created by a localscript.

What i should do instead? Could you provide me a code please? @Razorter

Can I ask what’s your scenario? Why do you need a server script to see the contents of a ScreenGui?

Because I’m making a shop system, and the server script is not finding the frame which is created by a local script. And the frame have some important values. (Has bought, cash, rarity, etc.)


@uJordy @MrLegendaryDoge

The server script won’t find an object which has been created by a local script. This is the principles of Filtering Enabled
You’ll need to use a remote event to send the data which contains your important values to the server so that you can deal with it with your server script.

Please do also remember that handling any significant data on the client can be manipulated. It’s safe to handle this data on the server whereby you can do checks to make sure that you don’t have any bad data.

1 Like

Then you shouldn’t be sending the frame itself to the server but the data itself like the cash, rarity ect.

Well, the problem is Has bought value which the gui identifies when the player has bought something, and it’s an easier way for me to manage the frames, well, but I have a question: it’s possible change this local script to a server script?


@HilyrHere I personally prefer keep everything in a frame.

Surely you’d use the server to declare if a player has bought an item? If so, then you can gain the data from the server script where you got the “HasBought” data

You might be over- complicating it more than it needs to be. We can help you out if you send us a repro and we can recommend what works best.

Most likely not, chances are you’ll need to redesign how you’re making this solution.

As I said in an earlier reply, anything related to GUI should be done on the client. The server should be responsible for keeping track of stuff like what the player bought, how much money they have, etc. All the client should be doing is sending messages to the server saying “player wants to buy THIS” where the server would handle the actual transaction. If you need the GUI to change in response to the transaction you could use a RemoteFunction instead of a RemoteEvent to send any important data back to the client.

What do you mean with repro?


@Blokav

Yeah, but the problem is that the server cannot get the frames cloned from the local script.

What do you need the server to do with the frames?

set has bought value to true, and change some texts. Right now I don’t know if the script set more stuff, since in in phone.

You could use a RemoteFunction to invoke the server to handle the transaction, then have it return a confirmation to the client so that the local script can make those changes.

Yeah, but how? Everybody is saying that I should use events, but how.

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

I saw that post time ago, but I want to know what I should specifically do, since I’m new at events…

Client can change those stuff, but will not be replicated in the server since FilteringEnabled is on. Otherwise, leaderstats might have never existed.