Touched and TouchEnded problems

Basically, when I fly inside the box or jump, it’s just team me like from the playersTeam to Lobby, and from Lobby to playersTeam.

local Part = script.Parent
local LobbyTeam = game.Teams.Lobby
local PlayersTeam = game.Teams.Contesters
local Players = game:GetService("Players")

Part.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		player.Team = PlayersTeam
	end
end)

Part.TouchEnded:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		player.Team = LobbyTeam
	end
end)
3 Likes

Touch and TouchEnded are not the greatest for these type of stuffs, i’d suggest you learn about raycasting, or use ZonePlus module by ForeverHD

4 Likes

Thank you! I really need to learn raycasting.

2 Likes

Another method I can suggest is to use RunService with workspace:GetPartBoundsInBox() where you can check if the player is within the zone based on CFrame and Size.

which looks something like this (im on mobile so there cld be some typos):

RunService.Heartbeat:Connect(function()

local parts = workspace:GetPartBoundsInBox(CFrame of Zone, Size of Zone)

local PlayersContesting = {}

for _, v in pairs(parts) do
if players:GetPlayerFromCharacter(v.Parent) then
table.insert(PlayersContesting, v)
v.Team = game.Teams.Contesters
end
end

for _, plr in pairs(Players) do
if not table.find(PlayersContesting, plr) then
plr.Team = game.Teams.Lobby
end
end

end)

this works like a check on who is in the zone

edit: i got nothing to do rn and im bored so i thought id suggest some script ideas to help xD

3 Likes

Thank you for your assistance as well! I thought about using the RunService, but I believe there would be lags and other issues, so I am currently using the ZonePlus module, which is simple to use.

3 Likes

GetTouchingParts() would be better because it gets only can collide objects and because of this it will be faster.

2 Likes

thats true but i usually use overlapparams for this get parts then just use a params which refer to my own collision group which is for player character parts only xD

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.