Trouble with regional gui

Ok

local hitboxpartz = workspace.Area:GetChildren()
local plrsInPart = {}

local function plrInPart(part)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
    if plr then
        return plr
   end
end

local function onTouch(part)
 local plr = plrInPart(part)
    if plr and not plrsInPart[plr.Name] then
        table.insert(plrsInPart, plr.Name)
        -- Code logic
    end
end

local function onTouchEnd(part)
    local plr = plrInPart(part)
    if plr and plrsInPart[plr.Name] then
        table.remove(plrsInPart, plr.Name)
        -- Code logic
    end
end

for i, v in pairs(hitboxpartz) do
    if v:IsA("BasePart") then
        v.Touched:Connect(onTouch)
        v.TouchEnded:Connect(onTouchEnd)
    end
end
1 Like

I have updated my example since it was incorrect it should now work perfectly fine.

1 Like

Whenever I enter the box, no gui pops up. Am I supposed to place that script somewhere else? Also, just saying the text is supposed to fade away and not tween or something. No errors show up in the output when I test it though.

1 Like

Please show me where the gui is placed so I can assist you

1 Like

Screenshot 2022-08-08 100352
Nothing works, mostly everything in the script is orange underlined and I need it to fade out, not tween.

1 Like

Okay please wait I’ll find a way to make this.

My example script only works on a normal script in workspace or ServerScriptService.

sorry i meant to send that to the other person

Mine too is a server script not a client script.

But your code does not work, I said I want every single piece of my code to be in one local script and not 2. Not to be rude but this is the 2nd time I asked so if you want to stop helping you can.

if it is a local script doesnt that mean it only shows for one person that is in the box? if it is a regular script doesnt that mean it shows for the whole server? i just want it to show for the person who is currently in the box

I’ll stop since i think you are overcomplicating thid very simple thing.

How am I overcomplicating it? I think you are if I’m being honest. I literally said twice that I just want it to be in 1 script, 1 part not 2 separate things. Every time it’s a script that has to do with something not even related to what I’m doing. You’re overcomplicating what I’m simply asking very nicely until now.

My script hooks the player added which gets fired when a player joins the game. The player then gets hooked to the character added to wait for the character to load and get the position of it. After it uses a while true do wait() loop to run until the character disappears normally when the player dies. The rest just handles the gui for that player. But you can handle guis on the server and on the client. I prefer to hook them on the server because the server hooks dont get sent to the client so its harder to make cheats for games if it is handled on the server with only the events on the gui that can also be put from a localscript. In short, no it isnt for the whole server but more for the players. If you want it for a localscript I can make it like that. Just tell me.

Thank you so much for helping and yes I would like it to be in a LocalScript. I just think it’s better that way because that’s the way I intended it to be. Maybe you could try to use my original code but just add the stuff that I asked to in it? Or just create new code for one LocalScript but that’s all I think just make sure it fades away like in my original code you might want to copy and paste it from mine into yours.

I tried to do what your script says it will do but I had to change a few things + I used TweenService but it works.

local function isInside(position1, position2, size2)
	return (position1.X >= position2.X - size2.X / 2 and position1.X <= position2.X + size2.X / 2) and -- X Axis
		(position1.Y >= position2.Y - size2.Y / 2 and position1.Y <= position2.Y + size2.Y / 2) and -- Y Axis
		(position1.Z >= position2.Z - size2.Z / 2 and position1.Z <= position2.Z + size2.Z / 2)
end

local hitbox = game:GetService("Workspace").hitboxPart -- CHANGE THIS TO YOUR PART LOCATION
local plr = game:GetService("Players").LocalPlayer
local gui = plr.PlayerGui:WaitForChild("AreaGui")

plr.CharacterAdded:Connect(function(char)
	
	local debounce = false
	while char do
		wait()
		if isInside(char.PrimaryPart.Position, hitbox.Position, hitbox.Size) and not debounce then
			print("Player is inside")
			-- Add gui to the screen of the player
			gui.Enabled = true
			game:GetService("TweenService"):Create(gui.Title,TweenInfo.new(0.2*1), {TextTransparency = 0}):Play()
			debounce = true
		elseif debounce and not isInside(char.PrimaryPart.Position, hitbox.Position, hitbox.Size) then
			print("Player is outside")
			-- Remove gui from the screen of the player since the player is outside of the box
			game:GetService("TweenService"):Create(gui.Title,TweenInfo.new(0.2*1), {TextTransparency = 1}):Play()
			debounce = false
		end
	end
end)
local char = plr.Character
while char do
	wait()
	if isInside(char.PrimaryPart.Position, hitbox.Position, hitbox.Size) and not debounce then
		print("Player is inside")
		-- Add gui to the screen of the player
		gui.Enabled = true
		game:GetService("TweenService"):Create(gui.Title,
			TweenInfo.new(1), -- Seconds
			{TextTransparency = 0}):Play()
		debounce = true
	elseif debounce and not isInside(char.PrimaryPart.Position, hitbox.Position, hitbox.Size) then
		print("Player is outside")
		-- Remove gui from the screen of the player since the player is outside of the box
		game:GetService("TweenService"):Create(gui.Title,
			TweenInfo.new(1), -- Seconds
			{TextTransparency = 1}):Play()
		debounce = false
	end
end

Edit: This script is a LocalScript

Wait if she wants the script to be local script. Couldn’t you use the Humanoid.Touched event to detect if the local player is in then part?

This does not work at all, there is an orange underline at one of the lines, nothing shows up, and nothing works. No errors in output but it can detect when I’m inside and outside and that’s pretty much it.

I wouldn’t recommend using it since the .Touched event only fires when the player touches the border of the part. And .TouchEnded fires when the player is no longer touching the border of the box. Trust me I tested this method multiple times. If you don’t believe me I recommend you go try it on roblox studio:

  1. Create a Part make it big enough
  2. Make your script
  3. Make the part CanCollide to false
  4. Observe the results

I will try to understand by looking at your script but it doesn’t make a lot of sense.