Heyyy. I have a problem. I am currently trying to make a GUI that changes Players coins to any amount given by admins. Now, I am trying to get the Coin Amount from the PlayerGui, that is from the Admin. But I get following error:
15:17:53.964 - Infinite yield possible on 'Players:WaitForChild("Instance")' 15:17:53.965 - Stack Begin 15:17:53.965 - Script 'ServerScriptService.CoinChanger', Line 3 15:17:53.966 - Stack End
And it doesnt print the Coin Amount, which is for testing.
Thats the script.
local function CoinChange(player) print(player) local PlayerGui = game.Players:WaitForChild(player).PlayerGui.Admin.Admin.Coins.CoinsAmount.Value print(PlayerGui) end game.ReplicatedStorage.CoinChange.OnServerEvent:Connect(CoinChange)
Couple things wrong here, first off player is already defined so you dont have to Wait for it again cause it already exists.
Secondly you cannot do WaitForChild by passing an Instance, you'd have to use the name of the players.
Thirdly, PlayerGui is not replicated to the server by default so trying to access any Gui in there from the server is not going to work.
Your issue is being caused because when using :WaitForChild() -- it's expecting a string.. When you use :WaitForChild(player) -- Player is a player instance which is why that error... So you'd need to do :WaitForChild(player.Name)..
But as stated in FloweryMonkeyboy5 answer, there is no need to do this because 'player' is already that game.Players[player.Name]
-- Although this will work, I strongly recommend when working with guis, use localscripts Solution to your script
local function CoinChange(player) local playerGui = player:WaitForChild('PlayerGui') -- Do whatever you need to do with playergui here end game.ReplicatedStorage.CoinChange.OnServerEvent:Connect(CoinChange)
Here is my solution:
Local Script
local event = game.ReplicatedStorage:WaitForChild('CoinChange') local textbox = frame.TextBox local button = frame.Button button.MouseButton1Click:Connect(function() event:FireServer(textbox.Text) end)
Server Script
local event = game.ReplicatedStorage:WaitForChild('CoinChange') event.OnServerEvent:Connect(function(player,boxText) print(player.Name,'Fired the event! while"',boxText,'" is what was shown in the Textbox!') end)
Note: Remember if you use something like this for a custom chat, you MUST Filter your chat
if you have any questions, feel free to comment below!