Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

0
Make sure your using LocalScript KenUSM 53 — 6y
0
It is a localscript SilverCreeper58 23 — 6y
0
character is a redirection just use player.Character with a wait before it Bucwheed 37 — 6y
0
still not working SilverCreeper58 23 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

0
`attempt to index field 'LocalPlayer' (a nil value)` SilverCreeper58 23 — 6y
0
Edited it, you can try this instead. mattscy 3725 — 6y
0
Thanks so much! :D SilverCreeper58 23 — 6y
Ad

Answer this question