Basically im making a purchasable portal, the buying portal of the script is based on a leaderstat if the leaderstat is 0 the player doesn't teleport but instead gets a GUI asking him to buy access to the portal but if the leaderstat is 1 it teleports the player through. The problem i face is that after the player touches the portal and doesn't have access to the portal like if he wanted to check how much it costs the gui pops up and if you click cancel or no on the GUI it goes away but then the script doesn't respond, it doesn't pop up a GUI and doesn't teleport you through even if you have access to the portal. Heres my script:
local ting = 0 --debouncer function onTouched(hit) if script.Parent.Locked == false and script.Parent.Parent:findFirstChild('Part2').Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild('Part2').Locked = true --Debounce. local Pos = script.Parent.Parent:findFirstChild('Part2').tp2 if ting == 0 then --debounce ting = 1 --activate debounce local check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the portal if check ~= nil then --If a human is found, then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human local stats = user:findFirstChild("telestats") --Find the file for stats if stats ~= nil then --If stat exists then local cash = stats:findFirstChild("tele1") --Get stats if cash.Value == 0 then print("OMG ITS WORKING NO WAYYYY!") user.PlayerGui.Buy.Frame.Visible = true else if cash.Value == 1 then wait(0.5)-- delays time till teleporting so if player is still touching part the player doesnt spazz between the portals hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild('Part2').Locked = false -- one last debounce check and teleports player end end wait(3) end end end ting = 0 end end script.Parent.Touched:connect(onTouched)-- checks for anymore players that touch the part
i dont know what im doing wrong is there something i need to add? if you find the problem and fix it thanks ALOT!