#problem with TouchEnded() and telaporting

1 messages · Page 1 of 1 (latest)

hollow girder
#

so basicaly i ahve a script that telports players to the map and then after a while it telaports players back to the lobby and to prevent players from spawning in an occupied spawn i use an attribute called "In use" and it is supposed to turn false whenever the player isnt touching the part anymore but i realized that if the player gets telaported off of the part like if they are telaported to a map and are still on the part then the "In use" stays true and so no one can telaport there anymore.

#

there are other parts of the script but these are the parts that determine if a spawn is in use

deep karma
#

Instead of touch ended could you make a loop and check the spawn's touched parts to see if the player is included or not?

wheat jewel
#

maybe attributes?

#

like isUsed = true

deep karma
#

I think the problem they were having was determining when to set inUse to false

#

when the player is teleported away i guess

#

I will try to send some code but im on my phone

deep karma
# hollow girder so basicaly i ahve a script that telports players to the map and then after a wh...
local touching = {}
local inUseAttr = false
local inUse = false
spawn:setAttribute("inUse",false)
local thread=task.spawn(function()
while task.wait() do
local touching = spawn:GetTouchingParts()
inUse=false
for _,v in pairs(touching) do
local char = v.Parent
if not char:FindFirstChild("Humanoid") then continue end
if touching[char] then
  inUse=true
  break;
end
end
if inUse==inUseAttr then continue end
spawn:setAttribute("inUse",inUse)
inUseAttr=inUse
end
end)
spawn.Touched:Connect(function(hit)
local char=hit.Parent
if not char:FindFirstChild("Humanoid") then return end
if touching[char] then return end
touching[char]=true
end)
#

also need to set touching[char] to false if they arent found with GetTouchingParts

#

sorry for terrible format

half steppeBOT
#

studio** You are now Level 6! **studio

deep karma
#

but maybe you only need to do this? I dont think you even need the Touched function

task.spawn(function()
while task.wait(0.1) do
inUse=false
for i,v in pairs(spawn:GetTouchingParts) do
 if not v.Parent:FindFirstChild("Humanoid") then continue end
inUse=true
break
end
end
end)
hollow girder
#

lemme try

#

im a little confused on where to put this code

hollow girder
#

@deep karma

deep karma
#

so like

local function setupSpawns()
for _,spawn in pairs(workspace:WaitForChild("Spawns") do
if spawn.Name~="SpawnPoint" then continue end

task.spawn(function()
while task.wait(0.1) do
inUse=false
for i,v in pairs(spawn:GetTouchingParts) do
 if not v.Parent:FindFirstChild("Humanoid") then continue end
inUse=true
break
end
end
end)

end
end
#

srry if it takes me a minute im on mobile

#

but try that i guess

hollow girder
#

oh esiy

#

wait

#

alrighty

deep karma
#

oh and you also need to add this in to the loop somehow:

spawn:setAttribute("inUse",inUse)

so you can see if its actually in use in your other code

hollow girder
deep karma
#

i also forgot the map parameter though

hollow girder
#

yea i fixed that

#

im testing right now but im pretty sure its bugged

#

yea we forgot to add the setattributes

#

sense the setupspawns function is what gives them the attribute

#

or what used to ig lol

deep karma
#

so what i was trying to do was just loop to check if there was a player touching or not

hollow girder
#
local function SetUpSpawns(map)
    for _,spawn in pairs(map:WaitForChild("Spawns"):GetChildren()) do
            if spawn.Name~="SpawnPoint" then continue end

            task.spawn(function()
                while task.wait(0.1) do
                    spawn:GetAttributes("InUse", false)
                    for i,v in pairs(spawn:GetTouchingParts()) do
                        if not v.Parent:FindFirstChild("Humanoid") then continue end
                        spawn:GetAttributes("InUse", false)
                        break
                    end
                end
            end)

        end
end
SetUpSpawns(lobby)```
deep karma
#

Use SetAttribute not GetAttributes

hollow girder
#

ohw wait u right im dumb

#

its still not giving any of teh spawns the attribute

deep karma
#

are u talking about in the getAvailableSpawns function?

hollow girder
#

what if i made a whole other function that checks all of the spawns to see if they are touching something and i can call that when a player leaves and whenever people are telaported

half steppeBOT
#

studio** You are now Level 14! **studio

deep karma
#

if you are able to know whenever a player is teleported that should be good

hollow girder
#

its in the same script

#

sense its round based

#

and this is how the game looks ingame

#

ignore the stole assets from forsaken their placeholders lol

deep karma
#

ok ill look in a sec im not home rn but i almost am

hollow girder
#

alrighty ur good

deep karma
#

the second time u set it suppose to be true

#

but u dont have to do it the way i did

#

if u dont want

#

not even sure if it should work tho cause i cant test myself rn

#

ill be at my computer in a sec

hollow girder
#

i think ifixed it

deep karma
#

ok, do you know if it works?

hollow girder
#
local function checkSpawnUse(map)
    local spawnsFolder = map:FindFirstChild("Spawns")
    if not spawnsFolder then
        warn("cant find mapspawns:" ..map.Name )
        return
    end

    for _, spawnPoint in spawnsFolder:GetChildren() do
        if spawnPoint:IsA("BasePart") then 
            local isPlayerCurrentlyTouching = false
            local touchingParts = spawnPoint:GetTouchingParts()

            for _, partInContact in touchingParts do
                local character = partInContact:FindFirstAncestorOfClass("Model")
                if character and players:GetPlayerFromCharacter(character) then
                    isPlayerCurrentlyTouching = true
                    break 
                end
            end

            spawnPoint:SetAttribute("InUse", isPlayerCurrentlyTouching)
        end
    end
end
#

i added this and called it and it works

#

but do u think i shuold try ur way

deep karma
#

no, that looks good

#

should be better than running it in a loop

hollow girder
#

alr bet'

#

thanks man