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

Simple Question how to access a player gui.?

Asked by 5 years ago
repeat
wait(25)
for i, v in pairs(game.Teams.Runners:GetPlayers())do
v.Player.PlayerGui.RewardGui.Background.Visible = true
wait(189)
end
until false

This script will get players in runners team and will make a reward gui visible Dont Works? Maybe can you say how to acess a PlayerGui.

1 answer

Log in to vote
0
Answered by 5 years ago

How to use PlayerGui

You can't really use PlayerGui, however, you can use RemoteEvents to communicate between the server and client.

Hierarchy of Remote

Insert a RemoteEvent in game.ReplicatedStorage and name it ShowRewardGui. Let's get onto using the Remote

Client Sided Code

Insert a LocalScript in StarterGui.

--\\ Services
local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
--\\ Network Data
local showReward = repStorage:WaitForChild("ShowRewardGui")
--\\ Player Components
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local rewardGui = playerGui:WaitForChild("RewardGui")
local rewardBackground = rewardGui:WaitForChild("Background")

-- We are sending a request from the client to server using OnClientEvent
showReward.OnClientEvent:Connect(function() 
    rewardBackground.Visible = true
end)

Server Sided Code

Your code now has to change because of our change. New Code:

--\\ Services
local teams = game:GetService("Teams")
local repStorage = game:GetService("ReplicatedStorage")
--\\ Network Data
local showReward = repStorage:WaitForChild("ShowRewardGui")
--\\ Teams
local runnersTeam = teams:WaitForChild("Runners")

--\\ repeat <code> until false is the same thing as a while loop
while true do
    wait(25)
    -- Put an _ for the index in the for loop because we are not using it
    for _, teamPlayer in pairs(runnersTeam:GetPlayers()) do
        -- This is how we communicate between client and server
        showReward:FireClient(teamPlayer)
        wait(189) 
    end
end

Hopefully this has helped you

0
Thank you for accepting my answer saSlol2436 716 — 5y
Ad

Answer this question