Trying to make a buy zone for my game, but when the round begins, the round system selects the players’ teams, and they get teleported, when they touch the trigger, the frame does not open.
I cannot figure out as to why this happens as nothing appears in the output.
local localScript = script.Parent.Parent
local frame = localScript.Parent.ShopFrame
local timerText = frame:WaitForChild("ShopTimerText")
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local debounce = false
local hasOpened = false
local function formatTime(seconds)
local minutes = math.floor(seconds / 60)
local secs = seconds % 60
return string.format("%02d:%02d", minutes, secs)
end
local function OpenFrame()
if not debounce and not hasOpened then
debounce = true
hasOpened = true
frame.Visible = true
for timeLeft = 50, 1, -1 do
timerText.Text = formatTime(timeLeft)
wait(1)
end
frame.Visible = false
debounce = false
timerText.Text = ""
end
end
local function OnTouch(other)
local player = Players:GetPlayerFromCharacter(other.Parent)
if player then
OpenFrame()
end
end
local function onPlayerRespawn(player)
hasOpened = false
debounce = false
end
local function connectBuyZones()
local buyZones = CollectionService:GetTagged("BuyZone")
for _, buyZone in ipairs(buyZones) do
buyZone.Touched:Connect(OnTouch)
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
onPlayerRespawn(player)
end)
end)
connectBuyZones()
return OpenFrame
Help would be appreciated!