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

How do I Tween a gui from an onTouched function?

Asked by 6 years ago

I understand what im doing, but this is being a real pain. when i touch a certain brick, it is supposed to tween in a message, but it isnt... here is the script:

function onTouched(part)
    script.Parent.CanCollide = false
    local frame = game.StarterGui.ScreenGui.Frame
    frame:TweenPosition(UDim2.new(0.5,-175,0.5,-11),'Out','Quint',1)
    frame.Selfie.Image = "rbxassetid://1244936009"
    frame.Talker.Text = "You:"
    frame.Message.Text = "Hello, Anybody here?"
    wait(4)
    frame.Message.Text = "Guess No-One is here..."
    wait(4)
    frame.Message = "Im Hungry..."
    wait(3)
    frame.Selfie.Image = "rbxassetid://90267225"
    frame.Talker.Text = "Server:"
    frame.Message.Text = "Go into town and get something to eat."
    wait(5)
    frame:TweenPosition(UDim2.new(0.5,-175,10,11),'In','Quint',1)
end

script.Parent.Touched:connect(function(onTouched)

0
I have the script running on a wait loop in the starter gui for now, but the message is supposed to pop up when you walk through a door. JakePlays_TV 97 — 6y
0
whats the point of using onTouched(part) when you don't do anything with (part) in the script greatneil80 2647 — 6y
0
because it's my game and di can do what i want JakePlays_TV 97 — 6y

3 answers

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

First and foremost, this should be inside a local script since this script has the job of manipulating guis. Because of this, the script should also be in the StarterGui.

In addition, line three where you declare the frame variable is wrong because you are referencing the gui inside of the StarterGui when you should be doing it from the PlayerGui. Don't get confused between the two. StarterGui is like a container that you can put your guis in. When a player joins, the contents of StarterGui are automatically cloned into the player's PlayerGui. Each player has their own individual PlayerGui. What is being shown to each player is the PlayerGui and not the StarterGui.

Finally, there are some minor improvements that can be made to the function itself such as adding a debounce and checking if the the part that touched the brick is a character.

local debounce = false
local part = workspace.Part --Whatever you want to trigger the touched event

function onTouched(hit)
    if not debounce and game.Players:GetPlayerFromCharacter(hit.Parent) then
        debounce = true
        part.CanCollide = false
        local frame = script.Parent.ScreenGui.Frame
        frame:TweenPosition(UDim2.new(0.5,-175,0.5,-11),'Out','Quint',1)
        frame.Selfie.Image = "rbxassetid://1244936009"
        frame.Talker.Text = "You:"
        frame.Message.Text = "Hello, Anybody here?"
        wait(4)
        frame.Message.Text = "Guess No-One is here..."
        wait(4)
        frame.Message = "Im Hungry..."
        wait(3)
        frame.Selfie.Image = "rbxassetid://90267225"
        frame.Talker.Text = "Server:"
        frame.Message.Text = "Go into town and get something to eat."
        wait(5)
        frame:TweenPosition(UDim2.new(0.5,-175,10,11),'In','Quint',1)
        wait()
        debounce = false
    end
end

part.Touched:Connect(onTouched)
Ad
Log in to vote
0
Answered by 6 years ago

Assuming you're using a local script (which you should be doing or else the script will tween to every player in the game) then do this

local frame = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
0
would i do frame.Frame then for all of my frame references? JakePlays_TV 97 — 6y
0
also, it still doesn't work, it it the on touched event that is giving me trouble. It just wont work JakePlays_TV 97 — 6y
0
I hope there is an update for roblox studio when i restart it JakePlays_TV 97 — 6y
Log in to vote
0
Answered by 6 years ago

now i know how to do it, i have two options in this script, they are two buttons, option 1 and option 2. im trying to use an if function but it wont work. it is supposed to be this:

local debounce = false
local part = workspace.Fragilistic --Whatever you want to trigger the touched event

function onTouched(part)
    if not debounce and game.Players:GetPlayerFromCharacter(part.Parent) then
        debounce = true
        local frame = script.Parent
        frame:TweenPosition(UDim2.new(0.5,-175,0.5,-11),'Out','Quint',1)
        frame.Talker.Text = "???"
        frame.Message.Text = "Roar!"
        frame.Selfie.Image = "rbxassetid://453541880"
        wait(5)
        frame.Selfie.Image = "rbxassetid://1244936009"
        frame.Talker.Text = "You"
        frame.Message.Text = "~thinking~"
        frame.Option1.Text = "Run"
        frame.Option2.Text = "Say 'Who's there?'"
        if frame.Option1.Mousebutton1click:Connect(function()
                --script--
else if fame.Option2.MouseButton1Click:Connect(function()
        --script--
        end)
        wait(10)
        frame:TweenPosition(UDim2.new(0.5,-175,10,11),'In','Quint',1)
        wait()
        debounce = false
    end
end

part.Touched:Connect(onTouched)

but it wont work, i know this isnt part of the question, but if it could be answered that would be great!

Answer this question