I am trying to make a Tweened GUI that will, instead of on click of a button, a part that you touch. I've tried a lot of different scripts, but none seem to work.
The code that I usually use for when I click a button to Tween a Gui is this:
local frame = game.StarterGui.ScreenGui local toggle = false
1 | script.Parent.**MouseButton 1 Click**:connect( function () |
2 | if toggle = = false then |
3 | frame:TweeningPosition(UDIM 2. new(coords), 'Out / In' , 'Easing Style' , 1 ) |
4 | toggle = true |
5 | else |
6 | frame:TweeningPosition(UDIM 2. new(coords), 'Out / In' , 'Easing Style' , 1 ) |
7 | toggle = false |
8 | end |
9 | end ) |
* And yes I have tried changing the bold part to Touched.*
Anyways to help?
You've got some things wrong in there, I'll list them for you:
"TweeningPosition" is written instead "TweenPosition", "UDIM2" is written instead "UDim2", you don't need the commas for the numbers, just use Enum.EasingDirection.InOut
, same goes for the easing style: Enum.EasingStyle.Quad
, you can't tween entire gui's itself, you need to tween individual frames, and finally, you can use the Touched function, it will work with it.
1 | script.Parent.Touched:connect( function () |
2 | if toggle = = false then |
3 | frame:TweenPosition(UDim 2. new(coords), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1 ) |
4 | toggle = true |
5 | else |
6 | frame:TweenPosition(UDim 2. new(coords), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1 ) |
7 | toggle = false |
8 | end |
9 | end ) |
Please accept this answer if it helped. If anything is wrong, leave a comment on this answer, and I'll get to you.
Okay so first off you need to make a server script and put it inside the part.
1 | script.Parent.Touched:connect( function (hit) |
2 |
3 | end ) |
So that makes whatever is put inside to run when the part is touched. Assuming the parent of the script is the part.
Next because that is a server script and the server can’t access playergui we need to make a RemoteEvent
assuming the RemoveEvent is in Workspace and is named RemoteEvent we want to do the following inside of what we had.
1 | script.Parent.Touched:connect( function (hit) |
2 | if hit.Parent:FindFirstChild(“Humanoid”) then |
3 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
4 | game.Workspace.RemoteEvent:FireClient(plr) |
5 | end |
6 | end ) |
Now the following will be in a LOCALSCRIPT in starterGui
1 | game.Workspace.RemoteEvent.OnClientEvent:connect( function () |
2 | — Put the tween code here. (Remove this line) |
3 | end ) |
Didn’t test this as I am on phone so mind any typing mistakes.