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.
#problem with TouchEnded() and telaporting
1 messages · Page 1 of 1 (latest)
there are other parts of the script but these are the parts that determine if a spawn is in use
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?
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
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
** You are now Level 6! **
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)
sorry i was eating food
lemme try
im a little confused on where to put this code
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
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
yea ngl there is a couple things missing from this
are you sure? I feel like thats all you need.
i also forgot the map parameter though
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
so what i was trying to do was just loop to check if there was a player touching or not
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)```
Use SetAttribute not GetAttributes
are u talking about in the getAvailableSpawns function?
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
** You are now Level 14! **
if you are able to know whenever a player is teleported that should be good
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
ok ill look in a sec im not home rn but i almost am
alrighty ur good
in this code you set the attribute to false when it was suppose to be true
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
i think ifixed it
ok, do you know if it works?
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