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

why wont my script find the things inside playergui?

Asked by 5 years ago
Edited 5 years ago

i made a chat script that teleports me to a friend when i type a command out but it says that chat is not a valid memeber of playergui any idea on how to fix this?

if game.Players:FindFirstChild("kleppolek") then

if game.Players.kleppolek.PlayerGui.ChatFrame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.Text == "/me wk" then

game.Players.klepplek.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.world_kiIIer.Head.Position)

end

end

if game.Players:FindFirstChild("world_kiIIer") then

if game.Players.world_kiIIer.PlayerGui.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.Text == "/me klep" then

game.Players.world_kiIIer.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.kleppolek.Head.Position)

end

end

also when we tested the game in roblox servers it said that player gui is not a valid member of payer, why? this is a local script inside starterpack

0
I read on one of the answers on here once that "The server cannot see the descendants of playergui which is clientside" or so I think spearmint123 20 — 5y
0
the script is a client side and so is the playergui so it should see Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Hello! I'm BlackOrange3343 and I'll be helping you today.

A ServerScript is incapable of accessing the PlayerGui of a Player. In order to access the PlayerGui, you must use the Client in this case a LocalScript. If you wish to start from the server, then you must use a RemoteEvent to signal the Client to change what you want to change.

To fix this:

  1. Add a LocalScript to the client and make sure it can run and access the GUI.

Now in the Local Script:

local ReplicatedStorage = game:GetService('ReplicatedStorage')

ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
    -- Do Stuff here that you wanted to do
end)

and in the Server Script under the command line where you check if the command is correct do:

local RemoteEvent = Instance.new('RemoteEvent')
RemoteEvent.Parent = game.ReplicatedStorage
RemoteEvent:FireClient(Player) -- Make sure Player argument is actually 
game:GetService('Debris'):AddItem(RemoteEvent, 1)

With this, you are now able to communicate to the client from the server. Now you can adjust the code accordingly.

Hope this helped! Best of luck developer!

BlackOrange3343

PS: If it errors please comment the error.

0
i dont need remotes, its a client script with a local script, it just moves me to the other player location Gameplayer365247v2 1055 — 5y
0
You should still use a RemoteEvent and use the command on the server. BlackOrange3343 2676 — 5y
Ad

Answer this question