Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you edit a PlayerGUI?

**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

✓ Accepted answer

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)

2 comments

0

Wouldn't you use GetPlayers(), rather than GetChildren()?

0

Both would work but I've always used :GetChildren()

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!

4 comments

0

Winner is simply a script in workspace.

0

Ok i was wondering why you where disabling something

0

So do you have a solution or were you just simply curious?

0

Yes i just added my solution

This discussion is preserved as it was. New answers, comments, and votes are closed.