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

Make GUI appear on touch of a brick? CHECK NEWER ONE!

Asked by
Mystdar 352 Moderation Voter
10 years ago

I want a GUI to appear at the top of the screen when you touch the brick. However I would like it so when you touch a brick (This script is meant to go in the part you're touching) a GUI that is currently in the Starter GUI appears Like this: (So it starts with a transparency of 1, invisible) And it stays there until you are no longer touching that part, in which it fades out. Please tell me what the properties of the text should be too

If you have a more efficent method tell me! Please annotate everything as I am a beginner scripter. I also realize this is not the place to ask for scripts.

3 answers

Log in to vote
1
Answered by 10 years ago

For efficiency I would use a** for** statement

For example

for i = 1, 4 do    -- this would repeat the script under it 4 times
script.Parent.Transparency = script.Parent.Transparency + .25
wait(.25)
end -- ends the for statement

that above is a way more efficient version of what you had

and for the touch gui part. I would use UDim2.new instead of transparency for guis. Because if you just have the guis invisible you have another one thats visible. Sometimes it thinks you're clicking on the invisible one. So lets move it off the screen instead.

put this script in the part.

script.Parent.Touched:connect(function(hit)
end)

Thats the basic function. Now lets add the gui into the players playerGui.

timewait = 0
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humaniod") and timewait == 0 then --checking if what hit it is really a player.
hit.Parent:GetPlayerFromCharacter().PlayerGui.GUI.Frame.UDim2.new(0, 0, 0 ,0) --it may be PlayerGUI I just can't remember. And this path you need to change to the GUI name and the frame name. If its just a textlabel/button or whatever change it to that name. Then copy the position of the gui where you want it and paste it in the UDim2.new part of the script. MAKE SURE ITS IN THE SAME FORMAT AS IT IS IN THIS SCRIPT. PROPERTIES LIE!!! <-- make sure :P. 
timewait = 60
end
end) --we have the end with a ) after it because if you look up top at the function we never closed the function

while wati(1) do
timewait = time wait - 1
until timewait = 0
repeat

That took a lot of time writing. Please accept answer and point up :)

0
So are those last 12 lines the ones I need to put in the script? Mystdar 352 — 10y
0
And the script goes in the part that you touch, also where of screen is it, will it then slide on to the screen? Mystdar 352 — 10y
0
To slide into the screen you'd use http://wiki.roblox.com/index.php?title=Tweening trogyssy 221 — 10y
Ad
Log in to vote
4
Answered by 10 years ago

Ok, first of all for the transparency you can use the for loop which WOULD look like THIS in YOUR case c;

non generic for pairs need 2 arguments and the 3rd is optional.

A) Beginning number for loop

B) End number of loop

C) "Optional" how much it will add to i by every loop

In your case you do need c because otherwise it will be 1 by default.

oh and you need to DEFINE the LOCATION but I'll show you that soon.

for i  = 0, 1, .25 do
    GUI.Transparency = 1 - i
    wait(.25)
end

Then you would need it to wait 4 seconds in your case and reverse it

wait(4)
for i = 0, 1, .25 do
    GUI.Transparency = i --i changed it here to add not subtract like in the last one
    wait(.25)
end

We will do the wait 60 of this afterwards.

Now you need the function of when this is touched

function SetTransGUI(part)
end

the part parameter because when you touch a brick a parameter is passed in called "part" meaning the part that touched it.

Oh and this is phenomenon in which the ontouch is activated ALOT so you need to add a varaible that wont allow it to run again WHILE its running

local debounce = true
function SetTransGUI(part)
    if debounce then
        debounce = false
        --now the code wont run while its running do it doesnt repeat itself
        --stuff goes HERE
    end
end

Now heres the part when we acces the players GUI now we will need to verify first if the touched part is a PLAYER

local debounce = true
function SetTransGUI(part)
    if debounce then
        local human = part.Parent:findFirstChild("Humanoid")
        if human then
            debounce = false --we dont want it to set it to false if its just a PART.

    end
end

Now afterwards this is the CHARACTER. We need to get inside its player GUI. Now heres the part when you use a method called GetPlayerFromCharacter(character)

local debounce = true
function SetTransGUI(part)
    if debounce then
        local human = part.Parent:findFirstChild("Humanoid")
        if human then
            debounce = false
            local plr = game.Players:GetPlayerFromCharacter(part.Parent)

    end
end

Before we go ahead lets create a seperate function that takes the location and does the fade in and out

function FadeInOut(GUI)  --Parameter when calling the function
    --heres where the for loop we did before kicks in!
    for i  = 0, 1, .25 do
        GUI.BackgroundTransparency = 1 - i
        wait(.25)
    end
    wait(4)
    for i = 0, 1, .25 do
        GUI.BackgroundTransparency = i
        wait(.25)
    end
end

Now we call it in the other script

local debounce = true
function SetTransGUI(part)
    if debounce then
        local human = part.Parent:findFirstChild("Humanoid")
        if human then
            debounce = false
            local plr = game.Players:GetPlayerFromCharacter(part.Parent)
            FadeInOut(plr.PlayerGui.ScreenGui.Frame)
             --you can change that to the location of your own
    end
end

Now we add the wait 60 so its unusable until 60 seconds

local debounce = true
function SetTransGUI(part)
    if debounce then
        local human = part.Parent:findFirstChild("Humanoid")
        if human then
            debounce = false
            local plr = game.Players:GetPlayerFromCharacter(part.Parent)
            FadeInOut(plr.PlayerGui.ScreenGui.Frame)
             --you can change that to the location of your own
            wait(60)
            debounce = true
        end --dont forget the end! c;
    end
end

Now the part when you call this when this the parent of this script is touched

script.Parent.Touched:connect(SetTransGUI)

Now we put it all together.

local debounce = true

function FadeInOut(GUI) 
    for i  = 0, 1, .25 do
        GUI.BackgroundTransparency = 1 - i
        wait(.25)
    end
    wait(4)
    for i = 0, 1, .25 do
        GUI.BackgroundTransparency = i
        wait(.25)
    end
end

function SetTransGUI(part)
    if debounce then
        local human = part.Parent:findFirstChild("Humanoid")
        if human then
            debounce = false
            local plr = game.Players:GetPlayerFromCharacter(part.Parent)
            FadeInOut(plr.PlayerGui.ScreenGui.Frame)
             --you can change that to the location of your own
            wait(60)
            debounce = true
        end 
    end
end

script.Parent.Touched:connect(SetTransGUI)

And this would work but you would have to change the parameter of when you call the FadeInOut.

AND I CAME UP WITH THIS FROM THE TOP OF MY HEAD AND WHEN I TESTED IT WORKED ON TEH FIRST TRY >:D

+9001 c;

1
LOOOK TochiWasHere 10 — 10y
Log in to vote
1
Answered by
trogyssy 221 Moderation Voter
10 years ago

You're going to need a touched event, http://wiki.roblox.com/index.php?title=Touched

a debounce, http://wiki.roblox.com/index.php?title=Debounce

and a function. http://wiki.roblox.com/index.php?title=Function

Here's another useful link for this: http://wiki.roblox.com/index.php?title=Function#Event_Triggered_Functions

As for a more efficient way of changing the transparency, you can use a for loop: http://wiki.roblox.com/index.php?title=For_loop#For

local gui= --put the path to the gui here, in serverstorage or lighting or wherever you have it stored

script.Parent.Touched:connect(function(hit)
    if not db then
    db=true
    if hit.Parent:FindFirstChild("Humanoid") and Game.Players:FindFirstChild(hit.Parent.Name) then
        local clone=gui:Clone()
        clone.Parent=Game.Players[hit.Parent.Name]
        local frame=clone. --put the path from the ScreenGui item to the item you want to fade into the screen
        for i=1, 0, -0.25 do --the variable "i" will descend from 1 to 0, in increments of -0.25
            frame.BackgroundTransparency=i
            wait(.25)
        end
        wait(4)
        for i=0, 1, 0.25 do --now i goes from 0 to 1 in increments of 0.25
            frame.BackgroundTransparency=i
            wait(0.25)
        end
        clone:Destroy()
        wait(60)
    end
    db=false
    end
end)
0
I hate to be rude but can you make it say as long a you're touching the part? So it fades in and will fade out when the part has stopped being touched? Mystdar 352 — 10y
0
The text I want appearing is in the Starter GUI, Screen GUI, Frame, Text Mystdar 352 — 10y

Answer this question