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

How do I fix this insanely annoying problem where scripts work in studio but not game? [Solved]

So I have this Custom Chat GUI, but I've encountered a very annoying problem. When everything works fine in the studio, it doesn't in the game! I've done solutions such as adding repeat wait() until game.Players.LocalPlayer ~= nil , repeat wait() until game.Players.LocalPlayer:WaitForChild("Character") , local ChildofPlayer = game.Players.LocalPlayer:FindFirstChild("Character") , at the beginning. Even adding a wait() at the beginning and end didn't help. This has really gotten me very annoyed and I've tried to research this for over a day. Also, nothing shows up in Output except some infinite yield error when I use a WaitForChild.

local Player = game.Players.LocalPlayer
local ChildofPlayer = Player:GetChildren("Character")
local chatbox6 = script.Parent.Parent.MsgChatFrame.chatbox6

script.Parent.msgbar.FocusLost:Connect(function(enter)
	if enter then
		script.Parent.Parent.MsgChatFrame.chatbox1.Text = script.Parent.Parent.MsgChatFrame.chatbox2.Text
        script.Parent.Parent.MsgChatFrame.chatbox2.Text = script.Parent.Parent.MsgChatFrame.chatbox3.Text
        script.Parent.Parent.MsgChatFrame.chatbox3.Text = script.Parent.Parent.MsgChatFrame.chatbox4.Text
        script.Parent.Parent.MsgChatFrame.chatbox4.Text = script.Parent.Parent.MsgChatFrame.chatbox5.Text
        script.Parent.Parent.MsgChatFrame.chatbox5.Text = script.Parent.Parent.MsgChatFrame.chatbox6.Text
        script.Parent.Parent.MsgChatFrame.chatbox6.Text = script.Parent.msgbar.Text
        script.Parent.msgbar.Text = "Tap the \"/\" button or click here to chat"
		chatbox6.Text = "  "..Player.Name..": "..chatbox6.Text
	end
end)

Someone please help, because I can't stand it

4 comments

0

Make sure your using LocalScript

0

It is a localscript

0

character is a redirection just use player.Character with a wait before it

0

still not working

1 answer

✓ Accepted answer

GetChildren only returns a table of the children inside the instance; you can't enter the name of the child as a parameter. Instead, if you just want to search for a child, you should use FindFirstChild or WaitForChild. However, the Character is a property of the player that points to the character model, and is not actually inside the player. A good way to wait for the character is by doing something like:

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = plr.Character or plr.CharacterAdded:Wait()

This will set the character variable to the player's character if it has been loaded, otherwise it will wait for the character to be added and return it when it is.

3 comments

0

attempt to index field 'LocalPlayer' (a nil value)

0

Edited it, you can try this instead.

0

Thanks so much! :D

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