I have gamepass script in Serverscriptservice that basically just parents a button to a gui, the gui does is parented to a Replicated storage folder.
Another script will parent the gui from the Replicated storage folder to the Playergui but, the problem is that when the gui is parented to Playergui the button won’t be parented to the gui.
Here is the script (in serverscriptservice)
local mps = game:GetService("MarketplaceService")
local gamepassid = 21391533
game.Players.PlayerAdded:Connect(function(player)
if mps:UserOwnsGamePassAsync(player.UserId, gamepassid) then
script.shop:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background
script.exclusive:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background.Shop.Frame
else
script.button:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background.Shop.Frame
end
end)
game.ReplicatedStorage.GuiPurchasedEXCLUSIVE.OnServerEvent:Connect(function(player)
script.shop:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background
script.exclusive:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background.Shop.Frame
end)
Are there any errors in the output? You said that the GUI are in ReplicatedStorage, but in the script, you are mentioning that the GUI’s are inside the script?
Which part of the script does not work?
Is it this
or this?
Also, i dont think WaitForChild is the problem at all.
Hey @BabyNinjaTime, I thought “WaitForChild” was the issue because with “WaitForChild” the script should be waiting on the MainGui.
This is the the output error, as you can see the script tried to detect the MainGui but it did not detect it at all because the script ran before the gui could be parented to PlayerGui.
No that is not true. WaitForChild() (and FindFirstChild()) can be used in local scripts and server scripts (and module scripts as well), no matter where the scripts are located at (well local scripts should not be in ServerScriptService and other places but yea).
Yes, when I was trying to figure out why it would not work I checked from the server and the MainGui was part of my PlayerGui but the script never detected it (My guess is it tried to detect it to early)
If the case is that it detected it to early how can I fix it?
Okay, I found the problem. You are trying to clone the MainGui to PlayerGui on a LocalScript. Meaning that you are doing the stuff on the Client Side. The Server cannot detect Client changes, which is why the Server Script cannot find the MainGui in PlayerGui.
Hey man, sorry for replying so late, I actually got disconnected, and I had to go somewhere. But yea i am back from where I was and now I can help.
I will be replying again below once im finished.
Okay, so, you want to use remote events in this situation.
Insert a remote event in ReplicatedStorage, and rename it to GuiEvent (you can change the name if you want, but just make sure to change the name in the scripts too).
Then use this code for your LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Event = ReplicatedStorage:WaitForChild("GuiEvent")
if UserInputService.TouchedEnabled and not UserInputService.KeyboardEnabled then
Event:FireServer("onMobile")
elseif UserInputService.GamepadEnabled and not UserInputService.KeyboardEnabled then
Event:FireServer("onConsole")
else
Event:FireServer("onPC")
end
Now, insert a Server Script in ServerScriptService, and use the following code below:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Platforms = ReplicatedStorage:WaitForChild("Platforms")
local Event = ReplicatedStorage:WaitForChild("GuiEvent")
local TypePC = Platforms.PC
local TypeMobile = Platforms.Mobile
local TypeConsole = Platforms.Console
Event.OnServerEvent:Connect(function(player, PlatformName)
if PlatformName == "onMobile" then
local Clone1 = TypeMobile:WaitForChild("MainGui"):Clone()
local Clone2 = TypeMobile:WaitForChild("SafeZoneGui"):Clone()
local Clone3 = TypeMobile:WaitForChild("CameraGui"):Clone()
local Clone4 = TypeMobile:WaitForChild("AvatarEditor"):Clone()
Clone1.Parent = player.PlayerGui
Clone2.Parent = player.PlayerGui
Clone3.Parent = player.PlayerGui
Clone4.Parent = player.PlayerGui
elseif PlatformName == "onConsole" then
local CloneGui = TypeConsole:WaitForChild("Guithing"):Clone()
CloneGui.Parent = player.PlayerGui
elseif PlatformName == "onPC" then
local Clone1 = TypePC:WaitForChild("MainGui"):Clone()
local Clone2 = TypePC:WaitForChild("SafeZoneGui"):Clone()
local Clone3 = TypePC:WaitForChild("CameraGui"):Clone()
local Clone4 = TypePC:WaitForChild("AvatarEditor"):Clone()
Clone1.Parent = player.PlayerGui
Clone2.Parent = player.PlayerGui
Clone3.Parent = player.PlayerGui
Clone4.Parent = player.PlayerGui
end
end)