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
script.Parent.**MouseButton1Click**:connect(function() if toggle == false then frame:TweeningPosition(UDIM2.new(coords), 'Out / In', 'Easing Style', 1) toggle = true else frame:TweeningPosition(UDIM2.new(coords), 'Out / In', 'Easing Style', 1) toggle = false end 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.
script.Parent.Touched:connect(function() if toggle == false then frame:TweenPosition(UDim2.new(coords), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1) toggle = true else frame:TweenPosition(UDim2.new(coords), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1) toggle = false end 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.
script.Parent.Touched:connect(function(hit) 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.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild(“Humanoid”) then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) game.Workspace.RemoteEvent:FireClient(plr) end end)
Now the following will be in a LOCALSCRIPT in starterGui
game.Workspace.RemoteEvent.OnClientEvent:connect(function() — Put the tween code here. (Remove this line) end)
Didn’t test this as I am on phone so mind any typing mistakes.