I have many locations, and i want to make title which will show in which location player is currenly. Is there any effective methods?
Can you explain in more detail what you mean by “location”?
Sorry for bad explanation, location is the specific place which stored in workspace, for example, city or forest
No worries.
This is my implementation, do not take it as “certainly effective”.
I assumed you wanted a client-sided implementation since you want visuals only.
This will probably still work if the player is dead and the character did not respawn yet, add a check for that if that is not desired.
PLEASE test it as well (do not hold me responsible for anything ).
--[[
This LocalScript is inside a ScreenGui, make sure
to set the ResetOnSpawn property of the ScreenGui
to false to prevent it from deleting the LocalScript
when the character respawns.
]]
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Zones = workspace:WaitForChild("Zones") -- Main folder for all the zone folders.
local CurrentZoneFolder = nil -- The folder of the zone that the character is currently in.
-- Only check the descendants of the Zones folder.
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Include
overlapParams.FilterDescendantsInstances = {Zones}
--[[
Example of how you could manage this in Workspace:
Workspace
-> Zones (Folder)
-> Zone1 (Folder) (Add an attribute called "Priority".)
-> Part (You can also use any BasePart.)
Part
Part
-> Zone2
-> Part
Part
]]
local function CheckZonesForCharacter(Character)
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local runConnection = RunService.Heartbeat:Connect(function()
local ZoneFolderFound = nil
for _, ZonePart in workspace:GetPartsInPart(HumanoidRootPart, overlapParams) do
--[[
If there are overlapping zones, you can set the
ZoneFolderFound to the one with the highest Priority,
which would be an attribute you set in the
zone folder of the BasePart.
]]
if ZoneFolderFound == nil or ZonePart.Parent:GetAttribute("Priority") > ZoneFolderFound:GetAttribute("Priority") then
ZoneFolderFound = ZonePart.Parent
end
end
if ZoneFolderFound == nil and CurrentZoneFolder ~= nil then
-- Replace with whatever display functionality you want...
print("Left " .. CurrentZoneFolder.Name .. " and not in a zone anymore.")
end
if ZoneFolderFound ~= nil and CurrentZoneFolder ~= nil and ZoneFolderFound ~= CurrentZoneFolder then
-- Replace with whatever display functionality you want...
print("Entered " .. ZoneFolderFound.Name .. " and left " .. CurrentZoneFolder.Name .. ".")
end
if ZoneFolderFound ~= nil and CurrentZoneFolder == nil then
-- Replace with whatever display functionality you want...
print("Entered " .. ZoneFolderFound.Name .. " and considered in a zone now.")
end
CurrentZoneFolder = ZoneFolderFound
end)
-- Disconnect the connection when the Character is removing to prevent the check from "duplicating".
Player.CharacterRemoving:Once(function()
runConnection:Disconnect()
runConnection = nil
end)
end
CheckZonesForCharacter(Character)
Player.CharacterAdded:Connect(CheckZonesForCharacter)
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local title = char:WaitForChild("Title name")
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
game:GetService("RunService").HeartBeat:connect(function()
title.Text = tostring(HumanoidRootPart.Position)
end)
end )
end )
wrote this script without a script editor
check for syntax errors
oh that
you can use region3 or you can put a part in that place and make it use .touched
you can do something like
for i,v in pairs(workspace.Folder:GetChildren()) do
v.Touched:connect(function(Part)
local char = Part.Parent
if not Char:FindFirstChildWhichIsA("Humanoid") then return end
local title = char:WaitForChild("Title name")
title.Text = v.Name
end)
end
this script is also written without a script editor
The idea is to just make you know what to do