#How to make dialogue script work when player character touches part?

1 messages · Page 1 of 1 (latest)

bleak gale
#

Hello, I am trying to make it so when a player touches the part with their character the dialogue begins
I've tried making it work but I am so unschooled in learning I have NO clue how to even figure it out

local say = {"You are now breathing manually"}
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local f = true
    if plr.PlayerGui.ScreenGui.Enabled == true or plr.PlayerGui.ScreenGui2.Enabled == true then
        f = false
    end
    if f == true then
        f = false
        plr.PlayerGui.ScreenGui.Enabled = true
        for i, v in pairs(say) do
            for i = 1, string.len(v) do wait(0.045)
                plr.PlayerGui.ScreenGui.TextLabel.Text = string.sub(v, 1, i)
                script.Dia:Play()
            end
            wait(string.len(v) / 10)
        end
        plr.PlayerGui.ScreenGui.Enabled = false
        plr.PlayerGui.ScreenGui.TextLabel.Text = (" ")
        f = true
    end
end)

(foregive me i have no idea what tags to use in this situation)

#

I tried replacing "ClickDetector.MouseClick:Connect(function(plr)" with "Touched:Connect(function(plr)"

#

And then below that with "if game:GetService('Players'):GetPlayerFromCharacter(script.Parent) then"

velvet merlin
#

is there any errors on the console?

bleak gale
#

Also please ping me

velvet merlin
#

what type of script is this? @bleak gale

#

and what is F used for?

#

okay i've found the solution i think @bleak gale

oblique shellBOT
#

studio** You are now Level 2! **studio

velvet merlin
#

F is used to see if the screenGUI is enabled or disabled

#

you should move F outside of the current scope

#

as every time you click the part it would become true even if the screenGUI is enabled

#

and may give problems

#

but its not really necessary

#

as in the if plr.PlayerGui.ScreenGui.Enabled == true or plr.PlayerGui.ScreenGui2.Enabled == true then it would make it false again

#

then

#

if its a local script

#

make it a server script (aka normal script)

#

join the 2 if's together using else

#

you would get something like this

#
local say = {"You are now breathing manually"}
local f = true

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if plr.PlayerGui.ScreenGui.Enabled == true or plr.PlayerGui.ScreenGui2.Enabled == true then
        f = false
    else
        f = false
        plr.PlayerGui.ScreenGui.Enabled = true
        for i, v in pairs(say) do
            for i = 1, string.len(v) do wait(0.045)
                plr.PlayerGui.ScreenGui.TextLabel.Text = string.sub(v, 1, i)
                script.Dia:Play()
            end
            wait(string.len(v) / 10)
        end
        plr.PlayerGui.ScreenGui.Enabled = false
        plr.PlayerGui.ScreenGui.TextLabel.Text = (" ")
        f = true
    end
end)```
#

now

#

i couldnt see if after script.Dia:Play() gave errors cause i didnt have that dialog

#

i tested it and it worked

bleak gale
#

Also thank you so much for the help

velvet merlin
#

ohhh

#

did it work?

bleak gale
#

Idk lemme try it

#

Also sorry for the late response I fell asleep

#

Nope didn't work

#

@velvet merlin

velvet merlin
#

Weird

#

It worked for me

#

Any errors on the console

bleak gale
#

No

#

Is there anything I should've put in the part?

#

Also please ping me

velvet merlin
#

well

#

why did you use click detector?

#

you have to use .Touched

#

so it would be like this

#
local say = {"You are now breathing manually"}
local f = true

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        if plr.PlayerGui.ScreenGui.Enabled == true or plr.PlayerGui.ScreenGui2.Enabled == true then
            f = false
        else
            f = false
            plr.PlayerGui.ScreenGui.Enabled = true
            for i, v in pairs(say) do
                for i = 1, string.len(v) do wait(0.045)
                    plr.PlayerGui.ScreenGui.TextLabel.Text = string.sub(v, 1, i)
                    script.Dia:Play()
                end
                wait(string.len(v) / 10)
            end
        end
        plr.PlayerGui.ScreenGui.Enabled = false
        plr.PlayerGui.ScreenGui.TextLabel.Text = (" ")
        f = true
    end
end)```
#

you may have to tweak the scopes a bit since coding in discord isnt very easy

oblique shellBOT
#

studio** You are now Level 3! **studio

bleak gale
# velvet merlin why did you use click detector?

Hey, I see you didn't ping me
PLEASE PING ME
But yes I did use click detector but I want to make it function when the player touches a part when they're using their body, thank you
PS:
This is the original script

local say = {"You are now breathing manually"}
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local f = true
    if plr.PlayerGui.ScreenGui.Enabled == true or plr.PlayerGui.ScreenGui2.Enabled == true then
        f = false
    end
    if f == true then
        f = false
        plr.PlayerGui.ScreenGui.Enabled = true
        for i, v in pairs(say) do
            for i = 1, string.len(v) do wait(0.045)
                plr.PlayerGui.ScreenGui.TextLabel.Text = string.sub(v, 1, i)
                script.Dia:Play()
            end
            wait(string.len(v) / 10)
        end
        plr.PlayerGui.ScreenGui.Enabled = false
        plr.PlayerGui.ScreenGui.TextLabel.Text = (" ")
        f = true
    end
end)
oblique shellBOT
#

studio** You are now Level 5! **studio

velvet merlin
#

Ohh, you want the player to touch the part and then, when the player touches the part, the click detector gets enabled and the player can click the part?

velvet merlin
#

Oh

#

Thats because the hit gets activated multiple times

#

Theres an easy way to fix that

bleak gale
#

Remove the part or script?

velvet merlin
#

Ill send u the code later cause rn im on mobile

#

So i cant really script

bleak gale
#

That's okay

velvet merlin
#

What is f used for?

bleak gale
#

Idk

velvet merlin
#

Ill read the entire script

#

Is screengui2 the outline or what is it

bleak gale
#

No it's another dialogue box

#

Idk why that is there

velvet merlin
#

Yeah

#

Well

#

If it doesnt really make sense in this context you can remove it

bleak gale
#

Huh

#

I never used to be able to do that

#

Otherwise a whole bunch of errors would surface

velvet merlin
#

What

#

If that dialogue is for another part or sm you dont need it scripted in that part

bleak gale
#

Thank you

#

For your help

velvet merlin
#

No problem

#

And why would you make an if statement that determines if f is false or.. false

bleak gale
#

I figured out ehat f is used for

#

It's to enable/disable touching the part

#

I think

velvet merlin
#

Oh

bleak gale
#

Nope

velvet merlin
#

But f is just debounce rn

#

Its a boolean paranted to nothing

#

But you cant disable hit neither

#

Not like click detectors

bleak gale
#

I'm so confused

velvet merlin
#

I shall just rewrite the whole script

bleak gale
#

Okay so

#

Oh okay

#

Sorry

velvet merlin
#

Sorry for what?

bleak gale
#

That you have to rewrite the whole script

velvet merlin
#

It's completely okay

#

Its my choice anyways

bleak gale
#

Okay

#

Thank you again

velvet merlin
#

Pretty sure f is for various uses

#

Per example, on the
if f == true then
you made f = false, after the for loop, you made it true

#

so it may be to determine if the loop is running?

#

idk f is confusing

#

@bleak gale

bleak gale
#

So it stops loop

#

Because the loop is used for when the text appears

velvet merlin
#

yeah

#

it doesnt stop it tho

#

the for loop is gonna continue to run and it will proceed after it finished

bleak gale
#

But I do want text to appear like in Undertale

#

What work arounds are there?

velvet merlin
#

It works fine pretty sure

oblique shellBOT
#

studio** You are now Level 4! **studio

bleak gale
#

But it makes a noise every time text appears

velvet merlin
#

But when it finishes the screengui will disappear so if i was you i'd add like a 1s wait or sm

bleak gale
#

?

velvet merlin
#

Anyways here is it

#
local say = {"You are now breathing manually"}
local opened = false

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then --if plr is not nil (doesn't exist) then it will continue
        if not opened then --basically opened == false
            opened = true --if the player hits the part again it won't open the gui, so it wont glitch
            plr.PlayerGui.ScreenGui.Enabled = true
            for i, v in pairs(say) do
                for i = 1, string.len(v) do wait(0.045)
                    plr.PlayerGui.ScreenGui.TextLabel.Text = string.sub(v, 1, i)
                    script.Dia:Play()
                end
                wait(string.len(v) / 10)
            end
            plr.PlayerGui.ScreenGui.Enabled = false
            plr.PlayerGui.ScreenGui.TextLabel.Text = (" ")
        else return end --if it's opened then the script will stop
    end
end)
bleak gale
#

Oh dang already?

#

Thank you

velvet merlin
#

ive added some information

#

according to my errors in the console it works

bleak gale
#

Thank you

velvet merlin
#

no problem

#

but test it still

bleak gale
#

So it works only once

velvet merlin
#

yes

bleak gale
#

Which is what I like for events like kicking or teleporting or something

#

So thank you for that

velvet merlin
#

no problem again

bleak gale
#

What's your Roblox username? I wanna credit you

velvet merlin
#

if you want it to be able to be opened then you can add a opened = false at the end of the "if not opened then" scope

bleak gale
#

Hmm

#

Your username is very familiar for some reason

velvet merlin
#

Add vixy or vixypaws cause im probably gonna change my username soon lol

#

When like my pending robux all come in

bleak gale
#

Nah I don't really need to

velvet merlin
#

My group funds have been on pending for over a month ;-;

bleak gale
#

Because past usernames exists

velvet merlin
#

My 300 rabax

#

😭

#

Hopefully they come in before i go on vacation

bleak gale
#

Hopefulyl

velvet merlin
#

Anyways good luck on your project :D

#

If you need help you can dm

bleak gale
#

Thank you

#

So fricken much

velvet merlin
#

No problemm lol

#

Put the solved tag btw

#

You forgot

bleak gale
#

How do I do that

oblique shellBOT
#

studio** You are now Level 6! **studio

bleak gale
#

Oh