I’m currently working on recreating the Wizard 101 battle system as a fun project and I have this kind of cool thing in it Animated GIF - Find & Share on GIPHY when a player touches an enemy it spawns the battle area and starts the battle between the player and the enemy however as you can see there’s 4 spots on each side this is because other players and enemies will be able to join the battle if they enter the battle area if those spaces are available of course. Although I handle the enemies on the server in a script
This is the code I have for the touch stuff (it’s a local script btw)
--For when player touches enemy that isn't in battle (so starting a battle)
for i,v in pairs(workspace.Enemies:GetChildren()) do
v.Humanoid.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not v:FindFirstChild("In Battle") then
if deb == false then
local player = players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
deb = true
print(player,v,"Start Battle - Client")
startBattle(player,v) --player that started it and the enemy
wait(2)
deb = false
end
else
print("Enemy In Battle")
end
end
end)
end
--Joining an existing battle by touching the battle area
spawn(function()
while wait(3) do
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "Battle Area" then
v.detection.Touched:Connect(function(hit)
print("Battle Area Detection Part Touched")
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("In Battle") == nil then
print("Humanoid Found & Not In Battle")
local player = players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
print(player,v,"Enter Battle - Client")
enterBattle(player,v)
else
print("Player Is Already In Battle")
end
end)
end
end
end
end)
Now this works however I just know 100% I could probably make this shorter and much nicer although I’ve just been unable to do that without breaking it
If anyone understands what I’m trying to do here and is able to help me make this not as messy and wack that would be great here’s the rest of the local script it’s just the other functions basically if you wanna know what enterBattle or startBattle is Local Script - Pastebin.com