Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)







0
Did you reset after you touched the ifTouchedStartGUI part? fluffyoreos32 63 — 4y
0
Yes, it just wont change at all. snipperdiaper 120 — 4y

4 answers

Log in to vote
1
Answered by
Misqueso 145
4 years ago

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
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
so I would just move the script into the local script replacing everything? snipperdiaper 120 — 4y
0
It doesnt work. snipperdiaper 120 — 4y
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. xInfinityBear 1777 — 4y
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. xInfinityBear 1777 — 4y
View all comments (16 more)
0
alr lemme check snipperdiaper 120 — 4y
0
Where is the Player scripts located? snipperdiaper 120 — 4y
0
Yes. If you put the local script inside StarterPlayerScripts then it will go into the Player's PlayerScripts xInfinityBear 1777 — 4y
0
It just wont work snipperdiaper 120 — 4y
0
I'll just try again snipperdiaper 120 — 4y
0
If your script is in StarterPlayerScripts, you may need to use a bunch of WaitForChild's. xInfinityBear 1777 — 4y
0
Yes, I've edited the code above accordingly. It should work now. xInfinityBear 1777 — 4y
0
No errors but the GUI wont show up from the 1 transparency's snipperdiaper 120 — 4y
0
Heres some gyazo's about the positioning and script 1: https://gyazo.com/e63e18a62326655d37dc6ddc88494369 -- 2: https://gyazo.com/52a20e5812227a5fcf8ab1c26dcb1c9d snipperdiaper 120 — 4y
0
Weird? I've got it set up the exact same as you and it works fine for me. xInfinityBear 1777 — 4y
0
Where is the part your touching located? xInfinityBear 1777 — 4y
0
Okay. The model is called FullBorderSandwich, and in your script above you've said SandwichBorderModel? Make sure the location of 'IfTouchedStartGUI' is correct. xInfinityBear 1777 — 4y
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. xInfinityBear 1777 — 4y
Log in to vote
0
Answered by 4 years ago
--// 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.

Log in to vote
-1
Answered by
synkrio 281 Moderation Voter
4 years ago

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.

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. snipperdiaper 120 — 4y
0
PlayerGui may not have loaded yet, as instances don't immediately load when a game starts. SilentsReplacement 468 — 4y

Answer this question