Help with making a script, when a player goes through a part a gui with a script inside it appears

Hello, I am currently working on a horror game. I need help with something. Basically, when a player goes through a part (non collide), I want the gui with my script from before(typewriting) to appear in the same place as before but starts typing a new text. However once the player goes through that part once I want it to not activate the gui again and only play all of the setTexts once.
My current script that plays the very first 3 typewriting setTexts


So I want that gui with the script to appear again like I said before but I am going to change the text.
Can anyone help me out please?

5 Likes

If I understood you correctly:
You want a player to go through a part, a GUI popup will appear with text only once?
And check if the player has already triggered it before to show different text?
Let me know if i didn’t.

1 Like

yes the GUI to appear, however I mean to check that the player has triggered it once so all the setTexts don’t repeat again and so the GUI doesn’t appear again I can just disable the visibility of it

1 Like

I am learning just can’t find the exact thing I want.

1 Like

That’s not a good answer. I guess he asked for help here not on youtube. If you don’t know how to help someone instead of talking nonsense just keep quiet.

1 Like

Learning how to script takes years so why would he do that just for this?

What do you mean?
Char30…

1 Like

I replied to @Baconphrases.
30 characters

Oh ok.
30charr…

1 Like

Okay so, if you want to achieve a simple popup GUI I recommend measuring the distance from the player to part every few seconds. If the distance is smaller than the minimal proximity make the GUI appear, also remember about making a new variable called for ex. debounce, set it to false at the beginning of the code.
This variable will change later to true when the player has reached the proximity of the part, so we’ll know that the player has already walked through it.

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() -- so we know that the player     character has been loaded.

local ScreenGui   = Player.PlayerGui:WaitForChild("ScreenGui")
local TextLabel   = script.Parent
local TriggerPart = workspace:WaitForChild("Trigger part name")

local Proximity = 10
local Debounce  = false

function setText(text)
    if typeof(text)=="string"then else warn("Argument[1] is not a string.") return false end
    for i = 1,#text do
    	TextLabel.Text = string.sub(text,1,i)
    end
    return true
end

while wait(.1) do
    local Distance = (Character.HumanoidRootPart.Position-TriggerPart.Position).Magnitude
    if Distance < Proximity then
	    if not Debounce then
	    	print("Player is close! Let's do it.")
	    	Debounce = true
		ScreenGui.Enabled = true
		setText("some text")
	end
end
end

Customize it so it fits your needs.
Might not work haven’t checked!

Can you not do it so when the player touches the part it loads the gui with the script without measuring distance?

It is possible to use .Touched event, but I suggest not doing so.
It can fire at random times without reason, it’s just not reliable…

Oh ok I will see if the script you made works.

Although .Touched event sometimes can have the text/frame glitching and it’ll look as if stuttering. I’m not sure if a table is needed, but what you can do is set the object CanCollide = true and flatten it out as if it were part of the floor, Transparency of the part set to “1”. Next, disable the localscript so when a player collides with part, it inserts the localscript/enables the localscript itself.
Keep in mind, you’ll have to make a table like this:

local myTable = {game.Workspace.Players.LocalPlayer}

Hope this helped, and if this didn’t work, I’ll see into it myself considering I am also working on something a bit similar as you! :smiley:

Have you figured it out yourself?
(30 chars)

Thank you, I will look into your script more later because I am currently working on camera shaking and tweening, it is going fine so far.

1 Like

No, I have tried but it does not work properly, I tried my own scripts but I am not done. don’t worky I will working in that part later.

It’s okay i understand that, but there are alot of different ways making the gui appear

  1. You can use .Touched and .TouchEnded (which is not recommended due to it’s bugginess)

  2. You can use Render Stepped and Magnitude (this is recommended)

  • Render Stepped is like .Touched but not buggy i guess, and magnitude the distance in studs before the gui dissapears,
  1. You can use Region3’s which i don’t recommend for your situation… I don’t know if they are the best because region3’s are through a server script and gui’s are never recommended to do on a server script…

RenderStepped and Magnitude Method (Recommended!)

  1. Make the gui/frame invisible
  2. Put the local script inside the gui/frame
  3. Make a triggerPart in workspace and make it invisible, anchored and collidable
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rs = game:GetService("RunService")

rs.RenderStepped:Connect(function()
	local toCompare = (char:WaitForChild("HumanoidRootPart").Position - game.Workspace.YOUR_TRIGGER_PART.Position).Magnitude
	if toCompare <= 3 then -- Change the "3" to the preferred Value of distance
	
		local guiFrame = script.Parent
		button.Visible = true
		
	else
		local guiFrame = script.Parent
		button.Visible = false
	end
end)

Region3 Method (not recommended)…

  1. Make a region part (like a hitbox for your whole trigger area)
  2. Put a normal script inside it
  3. Put this inside
local RegionPart = script.Parent
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1, pos2) -- This calculates the corner 1 of the trigger area and 2 and makes it a region

local player

game.Players.PlayerAdded:Connect(function(player) 
end)

while true do
	wait(0.1)
    local code = "unshow"
    game.ReplicatedStorage.someEvent:FireClient(player, code)

	local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			local char = part.Parent
			local player = game.Players:GetPlayerFromCharacter(char)
			if player then
				
                local code = "show"

                game.ReplicatedStorage.someEvent:FireClient(player, code)

				
			end
		end
	end
end


-- Make a Local script
local player = game.Players.LocalPlayer

game.ReplicatedStorage.someEvent.OnClientEvent:Connect(function(code)

   local gui = game.ReplicatedStorage.Gui:Clone() -- Make sure the "gui" is a screen gui

   gui.Parent = player.PlayerGui -- if it's a frame rather than screen gui, just do player.PlayerGui.ScreenGui

   if code == "show" then
      gui.Visible = true
   elseif code == "unshow" then
      gui.Visible = false
   end
end)

The RenderStepped method is recommended and way easier, if i didn’t cover something just mention it because i got way into this as i was writing it…

If you wanna use the Region3 method, please just make sure you’re doing it correctly and knowing what you’re doing because there’s some bugs there aswell and are weird to patch so yeah, i recommend you the renderstepped method

Cya!