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
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.
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
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
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: