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
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:
- 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.