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

My script wont turn the transparency of the GUI from 1 to 0?

it shows that GuiWinScript isnt a valid member of the model, everything (name wise and position in screenGui works. (all in one script)

local GuiWinScript = game.StarterGui.ScreenGui.YouWin
GuiWinScript.BackgroundTransparency = 1
GuiWinScript.TextTransparency = 1



game.Workspace.SandwichBorderModel.IfTouchedStartGUI.Touched:Connect(function()
	
	
	
    GuiWinScript.TextTransparency = 0
	GuiWinScript.BackgroundTransparency = 0.6
	
	
	
	
	
	
	
	
end)
	
	
	
	
	
	

2 comments

0

Did you reset after you touched the ifTouchedStartGUI part?

0

Yes, it just wont change at all.

4 answers

You are changing the GUI of the StarterGui which isn't the one the player sees.

Assuming that the script is a local script. You can refer to the correct GUI which is:

local GuiWinScript = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").YouWin

It's because you're changing the GUI that's in the StarterGui, and not in the PlayerGui. Every player has a PlayerGui, when they join the game everything in StarterGui gets moved into their PlayerGui. You have to get the player's PlayerGui and make changes to the GUI's that are in there.

Example: (ServerScript)

local Players = game:GetService("Players")

script.Parent.IfTouchedStartGUI.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- Checking if the thing that touched the part is a player, this will also detect NPCs.
		for _, Player in pairs(Players:GetPlayers()) do
			if Player.Name == hit.Parent.Name then 
				local PlayerGui = Player.PlayerGui
				local GuiWinScript = PlayerGui.ScreenGui.YouWin
				GuiWinScript.TextTransparency = 0
				GuiWinScript.BackgroundTransparency = 0.6
			end
		end
	end
end)

Another Example: (Local Script) Note, if this is in a local script, your local script has to be located in either, PlayerScripts, PlayerGui, the player's Character, Backpack or ReplicatedFirst. If the local script is inside the part, or in workspace then it won't work.

local Player = game.Players.LocalPlayer
local GuiWinScript = Player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("YouWin")

local IfTouchedStartGUI = game.Workspace:WaitForChild("SandwichBorderModel"):WaitForChild("IfTouchedStartGUI")

IfTouchedStartGUI.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		GuiWinScript.TextTransparency = 0
		GuiWinScript.BackgroundTransparency = 0.6
	end
end)

20 comments

0

so I would just move the script into the local script replacing everything?

0

It doesnt work.

0

My example is in a server script. If this was in a local script you could just do Local Player. I'll make another example for a local script.

0

Where is your local script located? LocalScripts only work inside PlayerScripts, PlayerGui, the player's Character, Backpack or ReplicatedFirst. If this is not in any of those then it won't work.

0

alr lemme check

0

Where is the Player scripts located?

0

Yes. If you put the local script inside StarterPlayerScripts then it will go into the Player's PlayerScripts

0

It just wont work

0

I'll just try again

0

If your script is in StarterPlayerScripts, you may need to use a bunch of WaitForChild's.

0

Yes, I've edited the code above accordingly. It should work now.

0

No errors but the GUI wont show up from the 1 transparency's

0
0

Weird? I've got it set up the exact same as you and it works fine for me.

0

Where is the part your touching located?

0

Okay. The model is called FullBorderSandwich, and in your script above you've said SandwichBorderModel? Make sure the location of 'IfTouchedStartGUI' is correct.

0

So it would be 'local IfTouchedStartGUI = game.Workspace:WaitForChild("FullBorderSandwich"):WaitForChild("IfTouchedStartGUI" )' Try that and see if it works. Also check if you get any 'infinite yields', sometimes they take a little bit to show up in the output, if you do get any, just send a screenshot or copy and paste the warning from the output to here.

--// Variables

local Player = game.Players.LocalPlayer

local playerGui = Player:WaitForChild("PlayerGui")

local GuiWinScript = playerGui:WaitForChild("YouWin")

GuiWinScript.BackgroundTransparency = 1

GuiWinScript.TextTransparency = 1


game.Workspace.SandwichBorderModel.IfTouchedStartGUI.Touched:Connect(function()

    GuiWinScript.TextTransparency = 0
    GuiWinScript.BackgroundTransparency = 0.6

end)


Please fix your indentation, also create variables if you want to reference something a lot. StarterGui is not what the player sees, it is immediately cloned to PlayerGui as soon as a player joins. PlayerGui is WHAT the player sees.

Conclusion:

Always create variables for clean code, as well as it makes referencing way easier.

StarterGui is not what the player sees.

If this is on a local script, try doing

local GuiWinScript = game.Players.LocalPlayer.PlayerGui.YouWin

When a player's character is loaded, the contents of StarterGui is copied to PlayerGui which is why the transparency did not change on the player.

2 comments

0

if the script (in local script) looks like this: local GuiWinScript = game.Players.LocalPlayer.PlayerGui.YouWin GuiWinScript.BackgroundTransparency = 1 GuiWinScript.TextTransparency = 1 game.Workspace.SandwichBorderModel.IfTouchedStartGUI.Touched:Connect(function() GuiWinScript.TextTransparency = 0 GuiWinScript.BackgroundTransparency = 0.6 end) then it doesnt work.

0

PlayerGui may not have loaded yet, as instances don't immediately load when a game starts.

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