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

How do you tween a GUI when a player touches a part?

Asked by 5 years ago
Edited 5 years ago

I'm having trouble tweening a GUI when a player's character touches a part. It seems that it should be fairly simple, but it has actually proven to be quite challenging. Here is the code I currently have in the part I want the character to touch:

local frame = game.StarterGui:WaitForChild("TeleportOptions").Frame
function onTouch()
    frame:TweenPosition(UDim2.new(0.11, 322, -0.2, 223), "Out", "Quint", 0.9, false)
    -- Test print statement to indicate that the block is being touched
    print("Part has been touched")
end
script.Parent.Touched:Connect(onTouch)

There are no errors showing in the output and the test print statement seems to be working. I'm not sure if it isn't working due to way the frame variable is being called or if the frame is being tweened too many times while the player touches the part multiple times.

I may be taking the wrong approach to the task, so if there is a better way of achieving the same goal, please let me know.

0
you should access the player's playergui and find the TeleportOptions frame there rather than accessing the startergui's TeleportOptions frame aipiox123 1 — 5y
0
im going to make it work then ill give you hte code VenyxAllDayBaby 0 — 5y

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Hello, Fillipko24!

Your problem is that you're changing StarterGui and not PlayerGui, also, you need to grab the character from the part that touched, to be able to get player PlayerGui

function onTouch(part)
   local plr = game.Players:GetPlayerFromCharacter(part.Parent) -- Tryes to grab player from the character
   if(plr)then--Test if is valid player
      local frame = plr.PlayerGui:WaitForChild("TeleportOptions").Frame
      frame:TweenPosition(UDim2.new(0.11, 322, -0.2, 223), "Out", "Quint", 0.9, false)
      -- Test print statement to indicate that the block is being touched
      print("Part has been touched")
    end
end
script.Parent.Touched:Connect(onTouch)

If I helped please upvote and accept the answer

Useful Links:

Starter Gui - Roblox Developer API

Player Gui - Roblox Developer API

Players:GetPlayerFromCharacter - Roblox Developer API

0
I'm afraid this does not work and now the test print statement does not work. The problem may be because of the script type. Does it have to be a local script in the part, or should a normal script work as well? Fillipko24 2 — 5y
1
It is a normal script on the part, local scripts only go on players/characters Leamir 3138 — 5y
0
Hmm... I'm using a normal script so I'm not quite sure what the problem is. I have the same frame moving with GUI text buttons on other GUIs, but it doesn't work when a player's character touches the part. Fillipko24 2 — 5y
0
You should check if the touched part's parent is owned by a player, not the part itself. :GetPlayerFromCharacter() determines a player through the entire model that is accessible through Player.Character. Afterl1ght 321 — 5y
View all comments (2 more)
0
Yes, I forgot to add the .Parent (Thanks, @Afterl1ght) Leamir 3138 — 5y
0
It worked! Thank you so much guys! Fillipko24 2 — 5y
Ad

Answer this question