local doorsfolders = game.Workspace.Map.Doors
local attempts = 0
local alreadytookprice = false
local uis = game:GetService("UserInputService")
for i, v in pairs(doorsfolders:GetChildren()) do
attempts = 1
if (v.EButtonPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude <= 30 then
script.Parent.Parent.Parent:FindFirstChild(v.Name.."Gui").Enabled = true
script.Parent.Parent.Parent:FindFirstChild(v.Name.."Gui").E.MouseButton1Click:Connect(function()
script.Parent.Visible = true
script.Parent.Title.Value = v.Name
script.Parent.Price.Value = v.Needed.Value
script.Parent.Yes.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Orbs.Value >= script.Parent.Price.Value then
if alreadytookprice == false then
alreadytookprice = true
game.Players.LocalPlayer.leaderstats.Orbs.Value -= script.Parent.Price.Value
print("already took price")
wait(1)
alreadytookprice = false
end
v:Destroy()
script.Parent.Visible = false
if attempts == 1 then
local result = game.ReplicatedStorage.EggHatchingRemotes.Door:InvokeServer(v.Name)
attempts = 0
end
end
end)
script.Parent.No.MouseButton1Click:Connect(function()
script.Parent.Visible = false
end)
end)
uis.InputBegan:Connect(function(key)
if key == Enum.KeyCode.E then
script.Parent.Visible = true
script.Parent.Title.Value = v.Name
script.Parent.Price.Value = v.Needed.Value
script.Parent.Yes.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.leaderstats.Orbs.Value >= script.Parent.Price.Value then
if alreadytookprice == false then
alreadytookprice = true
game.Players.LocalPlayer.leaderstats.Orbs.Value -= script.Parent.Price.Value
wait(1)
alreadytookprice = false
end
v:Destroy()
script.Parent.Visible = false
if attempts == 1 then
local result = game.ReplicatedStorage.EggHatchingRemotes.Door:InvokeServer(v.Name)
attempts = 0
end
end
end)
script.Parent.No.MouseButton1Click:Connect(function()
script.Parent.Visible = false
end)
end
end)
else
script.Parent.Parent.Parent.CityGui.Enabled = false
end
end
Im trying to figure out how I could make this script only run when the player join so its not running before because on the line
if (v.EButtonPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude <= 30 then
local doorsfolders = game.Workspace.Map.Doors
local attempts = 0
local alreadytookprice = false
local uis = game:GetService("UserInputService")
local localplr = game.Players.LocalPlayer
for i, v in pairs(doorsfolders:GetChildren()) do
attempts = 1
if (v.EButtonPart.Position - localplr:WaitForChild("Character"):WaitForChild("HumanoidRootPart").Position).Magnitude <= 30 then
script.Parent.Parent.Parent:FindFirstChild(v.Name.."Gui").Enabled = true
script.Parent.Parent.Parent:FindFirstChild(v.Name.."Gui").E.MouseButton1Click:Connect(function()
script.Parent.Visible = true
script.Parent.Title.Value = v.Name
script.Parent.Price.Value = v.Needed.Value
script.Parent.Yes.MouseButton1Click:Connect(function()
if localplr.leaderstats.Orbs.Value >= script.Parent.Price.Value then
if alreadytookprice == false then
alreadytookprice = true
localplr.leaderstats.Orbs.Value -= script.Parent.Price.Value
print("already took price")
wait(1)
alreadytookprice = false
end
v:Destroy()
script.Parent.Visible = false
if attempts == 1 then
local result = game.ReplicatedStorage.EggHatchingRemotes.Door:InvokeServer(v.Name)
attempts = 0
end
end
end)
script.Parent.No.MouseButton1Click:Connect(function()
script.Parent.Visible = false
end)
end)
uis.InputBegan:Connect(function(key)
if key == Enum.KeyCode.E then
script.Parent.Visible = true
script.Parent.Title.Value = v.Name
script.Parent.Price.Value = v.Needed.Value
script.Parent.Yes.MouseButton1Click:Connect(function()
if localplr.leaderstats.Orbs.Value >= script.Parent.Price.Value then
if alreadytookprice == false then
alreadytookprice = true
localplr.leaderstats.Orbs.Value -= script.Parent.Price.Value
wait(1)
alreadytookprice = false
end
v:Destroy()
script.Parent.Visible = false
if attempts == 1 then
local result = game.ReplicatedStorage.EggHatchingRemotes.Door:InvokeServer(v.Name)
attempts = 0
end
end
end)
script.Parent.No.MouseButton1Click:Connect(function()
script.Parent.Visible = false
end)
end
end)
else
script.Parent.Parent.Parent.CityGui.Enabled = false
end
end