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

PlayerGui is not a valid member of player?

Asked by 5 years ago

I've had to ask this many times so I am going to be as detailed as possible. I'm making a sell to player gui and this is under the StarterPlayerScripts:

01local Player = game.Players.LocalPlayer -- Getting the player  
02local Mouse = Player:GetMouse() -- Getting the players mouse
03 
04 
05Mouse.Button1Down:Connect(function() -- Detecting when player presses the left mouse button
06 
07    if Mouse.Target.Parent:FindFirstChild("Humanoid") and
08        Player.TeamColor.Name == ("Dirt brown") then -- Checking if the Mouse is over a player and on a selling team
09        print(Mouse.Target.Parent.Name) --Check  other player's name
10    local mousetarget = Mouse.Target.Parent
11local target = game:GetService("Players")[mousetarget.Name]
12        target.PlayerGui.StartScreen.Frame.Visible = true --Open other player's Gui
13        print("Debug") --Debug
14 
15    end
16end)

When someone clicks another player a gui pops up on the other players screen. I've been told to do remote events and more but this is the closest i have gotten. When clicking on another player I am given:

1PlayerGui is not a valid member of player --Line 12

1 answer

Log in to vote
1
Answered by
rexhawk 222 Moderation Voter
5 years ago

The answer for this is Remote Events

Remote events are like small doors to the server to execute specific functions that will replicate across all the clients (otherwise, changes you make on your client will STAY on your client)

To fix this (in other words, what I'd do), you'd fire a Remote event to the server telling the server that the player clicked another player. The server would receive this and tell the player that you clicked to display the GUI.

First, you'd need to put a remote event in ReplicatedStorage called "PlayerClickedPlayer" and put this script in ServerScriptService:

1--// Services
2local replicatedStorage = game:GetService("ReplicatedStorage")
3 
4replicatedStorage:WaitForChild("PlayerClickedPlayer").OnServerEvent:Connect(function(player,subject)
5    game:GetService("ReplicatedStorage"):WaitForChild("PlayerClickedPlayer"):FireClient(subject)
6end)

And this is your fixed code that you posted before (client script):

01--// Services
02local players = game:GetService("Players")
03local replicatedStorage = game:GetService("ReplicatedStorage")
04--// Objects
05local player = players.LocalPlayer
06local mouse = player:GetMouse()
07 
08mouse.Button1Down:Connect(function()
09    local player = players:GetPlayerFromCharacter(Mouse.Target.Parent)
10    if player and player.TeamColor.Name == ("Dirt brown") then
11        replicatedStorage:WaitForChild("PlayerClickedPlayer"):FireServer(player)
12    end
13end)
14 
15replicatedStorage:WaitForChild("PlayerClickedPlayer").OnClientEvent:Connect(function()
16    player:WaitForChild("PlayerGui").StartScreen.Frame.Visible = true
17end)

(Also improved some things for you)

Hope this helps

0
I can't get the server to connect Darksniper600 104 — 5y
Ad

Answer this question