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

Why won't this LocalScript make this ScreenGui tween?

Asked by 6 years ago
local block = game.StarterGui.ScreenGui.Frame

if workspace.Teleport1.Touched == true then
    function touched(player)
        local newgui = game.StarterGui.ScreenGui:Clone()
        newgui.Parent = player.PlayerGui
        newgui:TweenPosition(UDim2.new(0,0,0,0), 'Out', 'Bounce', 1)
        wait(2)
        newgui:TweenPosition(UDim2.new(0,0,-1,0), 'In', 'Bounce', 1)
        newgui:Destroy()
    end
end

This is a LOCALSCRIPT and is in StarterCharacterScripts, but for some reason, the script won't make the gui tween. It also ignores the if workspace.Teleport1.Touched == true then part, and just clones it to the PlayerGui anyways.

2 answers

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

So um...there are several problems I see in your script. So...

Problems

  • You’re using StarterGui instead of PlayerGui. StarterGui only replicates GUI to all players that join/respawn

  • The way you used that touched event on line 3 is completely wrong. That’s not how you use events. (Unless it’s a bool value. Correct me in the comments if so.)

  • You're tweening the ScreenGui itself, which you can’t do.

  • You’re using strings instead of enums. Strings can work I guess but it’s recommended to use enums.

  • You’re tweening by offset instead of scale. This may look okay for your screen and others like yours, but other screens like phones or other devices might see the GUI a bit weird.

Solutions

  • You could get the PlayerGui through LocalPlayer from the Players service. So line 1 can be something like local block = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame(Note LocalPlayer only works on local scripts)

  • Now, there’s actually several things you have to do on the touched event. First, you have to actually write it properly. Then, you’ll need to use something called remote events, which lets the server and client “communicate” with each other. You may ask, “Why do I need to use this?”. Well, that’s because the touched event doesn’t work on localscripts.

I’m not writing the scripts because this answer will just get way longer and I’m on mobile, so here’s some links to help you on this : https://www.robloxdev.com/articles/Remote-Functions-and-Events https://www.robloxdev.com/api-reference/function/Players/GetPlayerFromCharacter Also how to write functions and events properly : https://www.robloxdev.com/articles/Understanding-Functions-in-Roblox

  • Tween what’s inside the ScreenGui, not the ScreenGui itself.

  • Just use enums instead of strings. (Ex: Enum.EasingDirection.Out, Enum.EasingStyle.Bounce)

  • If you want the GUI to look the same on all other screens, then you should use scale instead of offset. Scale are the first and third number in UDim2, while the second and fourth number in UDim2 is offset (UDim2.new(scaleX, offsetX, scaleY, offsetY)). I recommend you use scale as that makes the GUI “fit” into other screens, instead of going off the screen.

Okay, so this was a bit long. I hope this helped though! If you have any questions, just comment.

0
I think my problem is the LocalScript thing. The top part of the function with the "==true" part, was just me trying out everything and hoping it works. Thanks for the help, though! MustangHeart 67 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

The reason why it isn't working is that you are attempting to tween the ScreenGui, not the Frame. ScreenGui's just hold Frames, the Frames are visible and the UI Part which you tween, ScreenGui's are not visible they just 'hold' the Frames.

The correct code to accomplish this is

local block = game.StarterGui.ScreenGui.Frame

if workspace.Teleport1.Touched == true then
    function touched(player)
        local newgui = game.StarterGui.ScreenGui:Clone()
        newgui.Parent = player.PlayerGui
        block:TweenPosition(UDim2.new(0,0,0,0), 'Out', 'Bounce', 1)
        wait(2)
        block:TweenPosition(UDim2.new(0,0,-1,0), 'In', 'Bounce', 1)
        block:Destroy()
    end
end

I hope I explained this alright and you understand. If that doesn't work reply again and ill check!

0
When I put it in startercharacterscripts, it does nothing. The gui is still cloned to my playergui, though. MustangHeart 67 — 6y

Answer this question