Accessing PlayerGui

Am I accessing PlayerGui correctly?

script.Parent.Touched:Connect(function()
	game.Workspace.Sound1.Clash:Stop()
	game.Workspace.Sound2.HorrorMusic:Stop()
	game.Workspace.Polcie:Stop()
	game.StarterGui.Transition.Frame.Transparency = 0
	wait(4)
	game.Players:GetPlayers().PlayerGui.Transition.Frame.Transparency = 0
	

end)

Can’t tell if its just a problem that can easily be fixed, or something that will take some time.

Please let me know if I am accessing PlayerGui correctly, if not please let me know how!

game.Players:GetPlayers() returns a table not a player

try this

script.Parent.Touched:Connect(function(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	game.Workspace.Sound1.Clash:Stop()
	game.Workspace.Sound2.HorrorMusic:Stop()
	game.Workspace.Polcie:Stop()
	game.StarterGui.Transition.Frame.Transparency = 0
	wait(4)
	player.PlayerGui.Transition.Frame.Transparency = 0
	

end)

One thing, before continuing make sure the player exists.
So:

script.Parent.Touched:Connect(function(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
    if not player then return end -- Guard clause
	game.Workspace.Sound1.Clash:Stop()
	game.Workspace.Sound2.HorrorMusic:Stop()
	game.Workspace.Polcie:Stop()
	game.StarterGui.Transition.Frame.Transparency = 0
	wait(4)
	player.PlayerGui.Transition.Frame.Transparency = 0
end
1 Like
script.Parent.Touched:Connect(function(Object)
    local player = game.Players:GetPlayerFromCharacter(Object.Parent)
    if not player then return end -- if it isn't a player, stop the function.
    --Stops the sounds
	game.Workspace.Sound1.Clash:Stop()
	game.Workspace.Sound2.HorrorMusic:Stop()
	game.Workspace.Polcie:Stop()

    --Remember to use `PlayerGui` when trying to access players GUI
	player.PlayerGui["FrameNameHere"].Transition.Frame.Transparency = 0
	task.wait(4) --delay between these 2 actions
	player.PlayerGui["FrameNameHere"].Transition.Frame.Transparency = 0
end)

@Valkyrop @domboss37 @Ashp116

None of these worked (probably not your guy’s faults) do I need to enable something in the settings? or does it have to be a local script? something like that…

1 Like

What was the error? Can u show me the workspace heiarchy

Please show us where it is located and relevant images from explorer[ so we might detect a misplaced instance or something]

Tho, I’d suggest using a local script and remotes if server sided is needed. [for better performance]


Script is located in a part in workspace
Ui is located in StarterGUI

Oh. I see,

You could simply use a local script[ since I dont see any server-sided needs here].
and clone the ui easier. [Put the gui under that local script]

game.Workspace.MyPart.Touched:Connect(function(Object)
    local player = game.Players:GetPlayerFromCharacter(Object.Parent)
    if not player then return end -- if it isn't a player, stop the function.
    --Stops the sounds
	game.Workspace.Sound1.Clash:Stop()
	game.Workspace.Sound2.HorrorMusic:Stop()
	game.Workspace.Polcie:Stop()

    
	script.Parent.Transition.Frame.Transparency = 0
	task.wait(4) --delay between these 2 actions
	script.Parent.Transition.Frame.Transparency = 0
end)

[You might need to adjust it to your gui frames etc]

Every player has their own personal PlayerGui, as you can see from this screenshot:

How it works is that every player’s PlayerGui contains their personal guis that only they see. If you only want one person’s gui to, for example, become transparent, you need to only modify the gui in their PlayerGui, but not anyone else’s.

game.Players.Player1.PlayerGui.Freecam.Frame.Transparency = 1

This makes only Player1’s frame transparent, but nobody else’s. So Player1 can’t see the frame anymore, but everyone else can.


This should work:

script.Parent.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- Player equals the player that touched the part

    if Player then
    	game.Workspace.Sound1.Clash:Stop()
    	game.Workspace.Sound2.HorrorMusic:Stop()
    	game.Workspace.Polcie:Stop()
    	game.StarterGui.Transition.Frame.Transparency = 0

    	wait(4)

        -- Modify the frame in the player who touched the part's playergui, so he alone sees it.
    	Player.PlayerGui.Transition.Frame.Transparency = 0
    end
end)

I just hope this helped you understand how PlayerGui works more.

Well. I do know the problem

script.Parent.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- Player equals the player that touched the part
    if Player then
    	game.Workspace.Sound1.Clash:Stop()
    	game.Workspace.Sound2.HorrorMusic:Stop()
    	game.Workspace.Polcie:Stop()
    	game.PlayerGui.Transition.Frame.Transparency = 0 -- Everyone made this mistake
    	wait(4)
    	Player.PlayerGui.Transition.Frame.Transparency = 1
    end
end)

This is a fix from his script because i believe he forgot to change the startergui
Also I’m pretty sure you make the transparency to 1 to make it invisible.

2 Likes

@ScriptingSausage @Valkyrop @niceeadam

None of these worked again… (again, not any of your guy’s faults, I do feel bad)

theres no errors or anything. I feel like everything should be working but isn’t.

I’ll fix this for you. It will look confusing, but it will fix your problem most likely.

Thank you. I don’t know whats going on. I feel as if everything should be working…

What do you need exactly? The Gui to appear than disappear after 4 seconds when you touch the part?

These three sounds stop playing

game.Workspace.Sound1.Clash:Stop()
		game.Workspace.Sound2.HorrorMusic:Stop()
		game.Workspace.Polcie:Stop()

Then the GUI appears then disappears after 4 seconds

game.PlayerGui.Transition.Frame.Transparency = 0 -- Everyone made this mistake
		wait(4)
		Player.PlayerGui.Transition.Frame.Transparency = 1

what I left off with, you can work off of this if you want:

script.Parent.Touched:Connect(function(Hit)
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- Player equals the player that touched the part
	if Player then
		game.Workspace.Sound1.Clash:Stop()
		game.Workspace.Sound2.HorrorMusic:Stop()
		game.Workspace.Polcie:Stop()
		game.PlayerGui.Transition.Frame.Transparency = 0 -- Everyone made this mistake
		wait(4)
		Player.PlayerGui.Transition.Frame.Transparency = 1
	end
end)

By the way, you want the sounds to be heard by only the player?

ya, it’ll be one player servers so I don’t think it matters.

Either way, I’ll do it on the client side.

1 Like

Alright here!
Tell me if there are any problems. If it works you can make this comment a solution.
Fix.rbxm (6.6 KB)

3 Likes