How do you access startergui from a workspace script

Recently I’ve had a problem where I’m unable to access a ui element thats located under Startergui from a script that’s located in Workspace and was wondering if any of you could help me. I’ve tried using player.playergui, but the script doesn’t recognize the player. If you guys could help I would really appreciate it.

5 Likes

u must use local scripts and use PlayerGui

2 Likes

The player’s gui is local. You can see it, but anything created on the client won’t show up for the server.

2 Likes

What are you trying to modify and from what context (client or server?)

StarterGui is just a storage and replication container for your UI, the instances in there are not the ones that are used at runtime. At runtime, each player gets a clone of the stuff in StarterGui, in their Player.PlayerGui. Each ScreenGui has a ResetOnSpawn property that determines if the same clone gets re-used when you respawn, or if it’s cloned again fresh from the StarterGui prototype.

Server and Client scripts can both modify a player’s PlayerGui, but only server changes will replicate to the player’s client, nothing replicates back from the client to server, so if you have a LocalScript modifying a player’s PlayerGui on their client, the server will not get those changes.

Scripts in the Workspace are executed on the server if they have RunContext of Legacy or Server, and execute on all clients if they have RunContext of Client. But a client Script running on a client will only be able to make local, non-replicating changes to that LocalPlayer’s PlayerGui only. Scripts on your client can’t modify another player’s gui.

2 Likes

Use a function to identify the player.

This function automatically gets the player and their PlayerGui.

game.Players.PlayerAdded:Connect(function(player)
  local playerGui = player:FindFirstChild("PlayerGui")
  local UiElement = playerGui:FindFirstChild("UiElement")
  --Change whatever properties you'd like
  UiElement.Visible = true
end) --If this doesn't work, try removing the bracket on this "end)" and make it just "end"

You could alternatively use this function to get the player. It really just depends on what you’re trying to accomplish. It would be helpful if you could give more context on your situation.

script.Parent.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
      local player = game.Players:FindFirstChild(hit.Parent.Name)
      local playerGui = player:FindFirstChild("PlayerGui")
    end
end)

Please let me know if this works for you.

1 Like

The problem is I’m trying to make it so when you touch a part your screen like cuts to black and in order to make it register that you touch a part is through a normal script, is there any work around for that?

1 Like

would that be in a local script or a normal script?

2 Likes

This is a client script inside the touch part.
If you are using Visible … that is on the frame.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:FindFirstChild(hit.Parent.Name)
		local playerGui = player:FindFirstChild("PlayerGui")
		playerGui:WaitForChild("UiElement"):WaitForChild("Frame").Visible = true
	end
end)
2 Likes

Thank you, that works perfectly.

1 Like

More @ FractalVortex
I just noticed you said visible … Keep in mind that script will hammer visible every time touched.
I left it that way as that may not matter to you. It will not error …

1 Like

My one question is is there anyway to make it backgroundtransparency instead of visible?

1 Like

That would be the label or button that would be inside the frame.

2 Likes

What I’m trying to say is I want it to like fade to black, not just cut straight to black, and I tried changing it to background transparency instead of visible but that didnt do anything at all.

2 Likes

Too hard to explain … Drop that in StarterGui (Insert from file). It shows really nice fade effects.
Fader.rbxm (5.6 KB)

Guess I didn’t need the startScreen = (this was a snip from old work)
Remove that line … Anyways, that is one way to do a fade in and out smoothly.
You may need to apply this to you label or whatever …

1 Like

I can take care of the effects I just need to know if theres a way to change the transparency of the gui from a normal script instead of just if its visible or not, sorry if I’m hard to understand.

1 Like

You should be able to … look at how them functions are working and apply that to the the frame or the label. So the frame would be visible and you’re changing the transparency like how them loops work.

local rs = game:GetService("RunService")
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:FindFirstChild(hit.Parent.Name)
		local playerGui = player:FindFirstChild("PlayerGui")
		local Frame = playerGui:FindFirstChild("UiElement").Frame
		if Frame.BackgroundTransparency == 1 then
			for i = 1, 30, 1 do	rs.Stepped:Wait()
				Frame.BackgroundTransparency = 1 - (i / 30)
			end	Frame.BackgroundTransparency = 0			
		end
	end
end)

That seems to fade in nicely …

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.