Why won't this work?

Heya! I’m experiencing an issue where although it clones the template and parents it. The Locked frame doesn’t disappear.

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

Please help, thanks!

5 Likes

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.

2 Likes

Oh, So#

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

would have to go into a different local script?

1 Like

You only need the event function in different local scripts located inside of each Locked Frame

1 Like

If I am not wrong, this script teleports players to the specified area when clicking onto the Unlocked Frame, right?

2 Likes

Yeah, it does!

Summary

This text will be hidden

1 Like
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

Paste this into each locked frame as a localscript and it will work

2 Likes

Yeah, but it loops through all the values in a folder. An “area” is just a value inside that folder

1 Like

You will have to make separate identifiers for area.

such as

local Area1 =game:GetService("Players").LocalPlayer:WaitForChild("Areas").Area1
2 Likes

Ill have to experiment because f how the script shown works. But ill try it out!

1 Like

Are there any console errors in this script?

2 Likes

You haven’t Played the TweenSize.

Template.Locked:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.3):Play()

Check above line and test if it resolved your issue

1 Like

sorry, just trying to experiment with this quickly

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

Try this also

1 Like

That works, thank you so much!

Mark it as a solution so the rest dont waste time in reading this post

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.