Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Game cant find the player in Script.?

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)

1 comment

0

you need to look into remote events and functions https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events :)

2 answers

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.

1 comment

0

Okay, but what can I do to get the value of the Textbox?

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.