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
8 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. ;/

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

Here's my second try.

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

3 answers

Log in to vote
0
Answered by
jotslo 273 Moderation Voter
8 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

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

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

1script.Parent.MouseButton1Down:connect(function()
2    script.Parent.Parent.Frame.Visible = true
3    wait(9)
4    script.Parent.Parent.Frame.Visible = false
5end)

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 8 years ago
Edited 8 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!

1local frame = script.Parent.Parent:WaitForChild('Frame')
2function onClick()
3frame.Visible = not frame.Visible
4end
5script.Parent.MouseButton1Click:connect(onClick)
Log in to vote
-1
Answered by 8 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