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

How do you edit a PlayerGUI?

Asked by 9 years ago

**THIS SCRIPT IS SUPPOSED TO RUN WHEN A PART HITS IT, NOT A PLAYER. ITS SUPPOSED TO SHOW A GUI ON THE PLAYER'S SCREEN WHEN A PART HITS ANOTHER PART**

This script won't work; I know why. I just dont know how to fix it.

function onTouched(hit)
    hit:Destroy()
    game.Workspace.Winner.Disabled = false
    game.StarterGui.ScreenGui.YouBeatTheLevel.Visible = true
end

script.Parent.Touched:connect(onTouched)

The issue is on Line 4. I am going to the StarterGUI rather than the PlayerGUI. Please note that there will only be one player in this game at one time. If you could fix this, I would very much appreciate it. Thank you!

2 answers

Log in to vote
4
Answered by 9 years ago

In order to do what you want you would do something like this and access the player by going through the child of Players.

function onTouched(hit)
    hit:Destroy()
    game.Workspace.Winner.Disabled = false
    for _, v in pairs(game.Players:GetChildren()) do
        v.PlayerGui.ScreenGui.YouBeatTheLevel.Visible = true
    end
end

script.Parent.Touched:connect(onTouched)

0
Wouldn't you use GetPlayers(), rather than GetChildren()? Relatch 550 — 9y
0
Both would work but I've always used :GetChildren() FearMeIAmLag 1161 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

You cant change a players active gui through startergui you need to use playergui, so with that said here is the fixed code:

function onTouched(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
local ply = game.Players:GetPlayerFromCharacter(hit.Parent)
local k = ply.PlayerGui:FindFirstChild("ScreenGui")
hit:Destroy()
workspace.Winner.Disabled = false
k.YouBeatTheLevel.Visible = true
end
script.Parent.Touched:connect(onTouched)

Hope i helped you!

0
Winner is simply a script in workspace. SchonATL 15 — 9y
0
Ok i was wondering why you where disabling something viralmoose 65 — 9y
0
So do you have a solution or were you just simply curious? SchonATL 15 — 9y
0
Yes i just added my solution viralmoose 65 — 9y

Answer this question