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

ANSWERED Why won't my tweening script for my GUI work in the Player? [closed]

Asked by 6 years ago
Edited 6 years ago

I have made myself a script that when clicked will animate the GUI off of the players screen and then a second after clicking destroy the script. When testing this out using the Studio it works perfectly and smooth however when I load the game in the Roblox Player or create a local server in the Studio the script does not function. The script is as follows:

script.Parent.MouseButton1Click:connect (function()
    script.Parent.parent:TweenPosition(UDim2.new(0, 0, -1, 0),"In","Quart")
    wait (1)
    script.parent.parent.parent:Destroy()

    pcall(function()
        local starterGui = game:GetService('StarterGui')
        starterGui:SetCore("TopbarEnabled", true)
        end)

end)

When the player clicks the button (which is the parent of the script) the GUI moves off the display, destroys and then the top bar becomes enabled (which is disabled when you first join the game).

EDIT: This question has been answered. Thanks everyone for the input.

0
Thank you both. I have added it into a localscript and it is now working. PureGamerGames 16 — 6y

Locked by Leamir, brokenVectors, and User#19524

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This script looks extremely messy:

First off When setting core it should be done in StarterPlayerScripts.

Secondly a few error you made in your script:

script.Parent.MouseButton1Click:Connect(function()

  1. Don't space out function()
  2. Use :Connect not :connect because :connect is deprecated

Next:

  1. Parent not parent

lastly:

  1. Give your tween a time

So your final script should look like:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent:TweenPosition(UDim2.new(0, 0, -1, 0),"In","Quad", 1) -- 1 second tween
    wait(1) -- no space
    script.Parent.Parent.Parent:Destroy()

    pcall(function()
        local starterGui = game:GetService('StarterGui')
        starterGui:SetCore("TopbarEnabled", true)
        end)
end)

Hoped this helped if you get any errors make sure to comment and tell me if it doesn't work debug by using print(). Also, make sure this is a local script.

Best of luck

0
Changing the CoreGui doesn't neccessarily have to be in StarterPlayerScripts as this effects changes in the StarterGui. When you put a script or whatever in StarterGui it is cloned to the PlayerGui of the player, so it's likely the same. SetCore will never affect all the clients when fired this way. SulaymanArafat 230 — 6y
0
I'm not saying it doesn't work I'm saying it "Should" be done in the StarterPlayerScript, this is because the StarterPlayerScripts never actually reset unlike the StarterCharacterScripts. Since this script in a GUI since we don't know if ResetGui is enabled or not it is safer to place it in StarterPlayerScripts. If it resets your just spamming a command that's not necessary. BlackOrange3343 2676 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I've fixed a bit your code.

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent:TweenPosition(UDim2.new(0, 0, -1, 0),'In','Quad',1)
    wait(1)
    script.Parent.Parent.Parent:Destroy()
    pcall(function()
        local StarterGui = game:GetService('StarterGui')
        StarterGui:SetCore("TopbarEnabled", true)
    end)
end)

Make sure it's in a LocalScript

Log in to vote
-1
Answered by 6 years ago

You need use Wait time in TweenPosition.

0
Ok really dude? BlackOrange3343 2676 — 6y