local ZoneWalls = workspace:WaitForChild("Areas"):GetChildren()
local Player = game:GetService("Players").LocalPlayer
local PlayersAreas = Player:WaitForChild("Areas"):GetChildren()
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
task.wait(1)
for _, area in PlayersAreas do
local Template = script._Template:Clone()
Template.Name = area.Name
Template.ZoneName.Text = area.Name
Template.Parent = script.Parent:WaitForChild("Container")
if area:IsA("NumberValue") then
area:GetPropertyChangedSignal("Value"):Connect(function()
if area.Value == 1 then
Template.Locked:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.3)
task.wait(0.3)
Template.Locked.Visible = false
Template.Teleport.MouseButton1Click:Connect(function()
HumanoidRootPart.CFrame = game.Workspace:WaitForChild("TeleportationLocators"):FindFirstChild(area.Name).CFrame
end)
end
end)
end
end
You have to make different localscripts for each of the Locked frame in order for it to work. Putting an event in for loop is not a good idea especially for a localscript.
if area:IsA("NumberValue") then
area:GetPropertyChangedSignal("Value"):Connect(function()
if area.Value == 1 then
Template.Locked:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.3)
task.wait(0.3)
Template.Locked.Visible = false
Template.Teleport.MouseButton1Click:Connect(function()
HumanoidRootPart.CFrame = game.Workspace:WaitForChild("TeleportationLocators"):FindFirstChild(area.Name).CFrame
end)
end
task.wait(1)
for _, area in pairs(PlayersAreas) do
local Template = script._Template:Clone()
Template.Name = area.Name
Template.ZoneName.Text = area.Name
Template.Parent = script.Parent:WaitForChild("Container")
if area:IsA("NumberValue") then
local function onValueChanged()
if area.Value == 1 then
Template.Locked:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.3)
task.wait(0.3)
Template.Locked.Visible = false
Template.Teleport.MouseButton1Click:Connect(function()
local playerCharacter = game.Players.LocalPlayer.Character
if playerCharacter then
local humanoidRootPart = playerCharacter:WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = game.Workspace:WaitForChild("TeleportationLocators"):FindFirstChild(area.Name).CFrame
end
end)
end
end
area.Changed:Connect(onValueChanged)
onValueChanged()
end
end