So I’m trying to do something with a .Touched event(?) and I’ve been having an issue. So I have a local script for which has this
for i,v in pairs(workspace.Enemies:GetChildren()) do
v.Humanoid.Touched:Connect(function(hit)
if deb == false then
if hit.Parent:FindFirstChild("Humanoid") then
print(hit)
if not v:FindFirstChild("In Battle") then
print("Enemy Is Not In Battle - Starting One")
local player = players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
print(player)
deb = true
startBattle(player,v) --player that started it and the enemy
else
end
end
end
end)
end
Heres the startBattle function
function startBattle(player,enemy)
local test = startBattleFunc:InvokeServer(enemy)
if test ~= nil then
local battleArea = test[1]
deck = test[2]
inhand = test[3]
local nearestPart = nil
local length = nil
for c,d in pairs(battleArea:GetChildren()) do
if d.Name == "Friendly" then
local lengthX = player:DistanceFromCharacter(d.Position)
if length == nil or lengthX < length then
length = lengthX
nearestPart = d
end
end
end
controls:Disable()
player.Character.Humanoid:MoveTo(nearestPart.Position)
spawn(function()
wait(1.5)
cameraTween(camera,battleArea.cam,2)
player.Character.HumanoidRootPart.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, enemy.HumanoidRootPart.Position)
playerGui.ScreenGui.Frame.Battle.Visible = true
end)
spawn(function()
timer()
end)
cardsFolder.Parent.Deck.Text = "Cards\n"..#deck.." of "..#deck+#inhand
for i,v in pairs(cardsFolder:GetChildren()) do
if v.Name == "TextButton" then
v.Name = inhand[i]
v.Text = inhand[i]
end
end
end
end
As you can see from the vide even though 1 player touched the dummy it runs the code for the 2nd player as well. I print the player on the server and it prints both players which makes no sense because again only 1 player touched it so shouldn’t it only effect 1?