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

Script won't work even though it is basic?

Asked by
Hydrogyn 155
7 years ago

I really don't know what is wrong with this but I tried 2 times to get it right. :/

Not sure if I got the ' script.Parent.MouseButton1Down:connect(function() ' wrong. ;/

script.Parent.MouseButton1Down:connect(function()
    game.StarterGui.ScreenGui.Frame.Visible = true
    wait(9)
    game.StarterGui.ScreenGui.Frame.Visible = false
end)

Here's my second try.

script.Parent.MouseButton1Down:connect(function()
    script.Parent.Frame.Visible = true
    wait(9)
    script.Parent.Frame.Visible = false
end)
0
Hmm, I think I might know the issue. Hydrogyn 155 — 7y
0
StarterGui is not active. Second one should have worked. cabbler 1942 — 7y
0
The second one should work. You shouldn't use StarterGui to set Gui's for players. Mayk728 855 — 7y

3 answers

Log in to vote
0
Answered by
jotslo 273 Moderation Voter
7 years ago

The reason your first attempt didn't work is because StarterGui is a bin. If you want to update something on a player's screen, you need to access the PlayerGui which is located in Game -> Players -> PlayerName -> PlayerGui.

If you would like to change something for every player, you could iterate through all players like this

for _,plr in pairs(game.Players:GetPlayers()) do
    plr.PlayerGui......
end

As for your second attempt, my only guess is that the parent of the script is the frame you're attempting to refer to. If this is the case, you should actually try the following

script.Parent.MouseButton1Down:connect(function()
    script.Parent.Parent.Frame.Visible = true
    wait(9)
    script.Parent.Parent.Frame.Visible = false
end)

Why? This is because your script was actually referring to a frame that is underneath the same parent as the script.

I hope this helps!

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Okay, the problem is that you don't have a WaitForChild. Without one, the script will only work in studio. Here is your corrected script in the most compact version it can get, enjoy!

local frame = script.Parent.Parent:WaitForChild('Frame')
function onClick()
frame.Visible = not frame.Visible
end
script.Parent.MouseButton1Click:connect(onClick)
Log in to vote
-1
Answered by 7 years ago

I think you have to replace visible with remove() not sure, I made this with animation, I hope this helps

local function OnClicked() script.Parent.Parent:TweenPosition(UDim2.new(-1.2, 0,0, 0),"In","Quint",10,true) end

script.Parent.MouseButton1Click:connect(OnClicked)

Answer this question