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