Attempting to call Buttons that was created sever-sided on a LocalScript

I want to be able to call ANY TextButton’s that was created server sided on a LocalScript. However, I can’t do that because the LocalScript simply doesn’t detect that those Buttons exist. I’m not sure whenever it is because it was created server-sided, but im assuming so since everything I’ve made server-sided can’t be found client-sided.

I can’t make these buttons client-sided as I am grabbing Tools from ServerStorage, which any in there disappear for the client and can’t be grabbed unless it’s through the server.

Here’s some code in case that helps:

local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local playersService = game:GetService("Players")

local toolsFolder = serverStorage:WaitForChild("ToolsFolder")

local shopGUI = script.Parent

local player

local selectedTool = nil

local function removeSpaces(str)
	return str:gsub(" ", "")
end

for _, tools in ipairs(toolsFolder:GetChildren()) do -- Creating tool infos
	local requiredToolModule = require(replicatedStorage.Modules.Tools:WaitForChild(tools.Name))
	if requiredToolModule.Weapon_IsSpecialWeapon then
		local toolTemplate = shopGUI.WeaponsUI.Weapons.S_Weapons.WeaponInfoExample:Clone()
		toolTemplate.Parent = shopGUI.WeaponsUI.Weapons.S_Weapons
		toolTemplate.Name = removeSpaces(tools.Name .. "Button")
		toolTemplate.Weapon_Name.Text = tools.Name
		toolTemplate.OtherInfo.KillsPrice.Text = "S-KILLS: " .. requiredToolModule.Weapon_KillsPrice
		toolTemplate.OtherInfo.PointsPrice.Text = "POINTS: " .. requiredToolModule.Weapon_PointsPrice
		toolTemplate.IsGamePass.Visible = requiredToolModule.Weapon_IsGamepass
		toolTemplate.Visible = true
	else
		local toolTemplate = shopGUI.WeaponsUI.Weapons.N_Weapons.WeaponInfoExample:Clone()
		toolTemplate.Parent = shopGUI.WeaponsUI.Weapons.N_Weapons
		toolTemplate.Name = removeSpaces(tools.Name .. "Button")
		toolTemplate.Weapon_Name.Text = tools.Name
		toolTemplate.OtherInfo.KillsPrice.Text = "KILLS: " .. requiredToolModule.Weapon_KillsPrice
		toolTemplate.OtherInfo.PointsPrice.Text = "POINTS: " .. requiredToolModule.Weapon_PointsPrice
		toolTemplate.IsGamePass.Visible = requiredToolModule.Weapon_IsGamepass
		toolTemplate.Visible = true
	end
end

replicatedStorage.Remotes.BuyTool.OnServerEvent:Connect(function(selectedTool)
	local toolBuyed = serverStorage.ToolsFolder:WaitForChild(selectedTool):Clone()
	toolBuyed.Parent = player.Backpack
	print("Gave", player, "tool", selectedTool .. ".")
end)

playersService.PlayerAdded:Connect(function(plr)
	player = plr
end)

This is the error it calls when I try to look through the folder that all the tools are in (client-sided):

localscripts that are trying to access the serverstorage will just get an empty parent, all children of it will be nil(this includes serverscriptsservice). try moving the folder over to replicatedStorage

Apologies if my explanation or title didn’t make you understand why I made this post. I want to find out how to call buttons that have been made server-sided on a LocalScript (client-sided). I have only provided the screenshot for those who don’t understand why i can’t just do everything client-sided.

Though, thank you for the suggestion. I should’ve definitely thought about that before; But this doesn’t solve my original problem where I cannot call buttons made server-wise. I’d like to know the solution to this for the future if possible. Much appreciated!

Dont worry, on what you said that the buttons are created serverside, could you approach on having the client code wait for said buttons be received to the player’s UI itself by the server and then run the logic for them

Oh, alrighty then I see. It looks like it worked. Apologies. Is there a way to yield the script until they are all fully loaded through? I believe wait() or wait.task() isn’t a good way considering everybody has different loading times.

Screenshots:


Edit: I didn’t provide the code for how I got these in the Output. Those are all done through the client :+1:

looking at the loop in getting the folder of the tools, i think you should just wait for them to get added to the main UI, dont check the whole folder, for example:

--instaed of
for _,tools in ipairs(toolsfolder) do [logic] end
-- you gonna have to run childAdded
mainUI.ChildAdded:Connect(function(x)
    if [x is classified as a tool button] then
       local requiredToolModule = require(replicatedStorage.Modules.Tools:WaitForChild(x.Name))
       --rest of the code referring x as a tool
    end
end)

this is how to verify its existence, youre almost there

I’m sorry, I’m not sure how to add on with this. Should this be ran through the ClientHandler instead of the ServerHandler? ServerHandler is what makes the Templates, and im trying to call all the templates made from the server in ClientHandler.

Here’s what the GUI looks like in explorer:

And the code block in the post is the ServerHandler script:

ChildAdded won’t work in the ServerHandler script since all the tools are manually placed inside the folder:
image

but you are going to call all the buttons in ClientHandler, then ChildAdded in the localscript will listen for every button created by ServerHandler, i am a little confused comparing the first code in the OP and the Explorer in your snapshot but what is aforementioned should get what you need

Ah, apologies. I got confused because you used an example that came from my ServerHandler, so I thought you were talking about using it in the ServerHandler rather than the ClientHandler. I will mark your reply as the solution since it did end up working!

I just ended up using a different method since ChildAdded runs everytime a child is added, which would lead to “devastating results” since I need to interact with said buttons.

ServerHandler:


ClientHandler:

Using ChildAdded would make that little section in the ClientHandler run multiple times when a button is clicked, which I didn’t want it to lead to that. (hence the devestating result). So, I instead yielded the LocalScript until a Bool existed.

My method actually detected when i clicked the button ONCE:

Nonetheless, you definitely helped me! Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.