Hi!
-
What do you want to achieve? I need to make a .Touched function stop early if the person who touched it dies.
-
What is the issue? I cannot seem to figure it out.
-
What solutions have you tried so far? I’ve tried using a
connection:Disconnect()
in atask.spawn
, but that for some reason makes it so the .Touched function only runs one time, and doesn’t work afterwards.
Here’s my code:
script.Parent.Touched:Connect(function(hit)
if game:GetService("ReplicatedStorage").CurrentCapturePoint.Value == "A" then
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr.TeamColor == BrickColor.new("Bright red") and script.Parent.BrickColor ~= BrickColor.new("Bright red") and script.Parent.ParticleEmitter.Enabled ~= true then
script.Parent.BrickColor = BrickColor.new("Bright red")
game:GetService("ReplicatedStorage").PointBeingCaptured:FireAllClients('A','Red',true)
task.spawn(function()
for i=1,20 do
if hit.Parent.Humanoid.Health == 0 then
script.Parent.BrickColor = BrickColor.new("Dark stone grey")
game:GetService("ReplicatedStorage").PointBeingCaptured:FireAllClients('A','Red',false,true)
script.Parent.ParticleEmitter.Enabled = false
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
end
wait(1)
end
end)
script.Parent.ParticleEmitter.Enabled = true
script.Parent.ParticleEmitter.Color = ColorSequence.new(Color3.fromRGB(255,0,0))
wait(15)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Enabled = false
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
game:GetService("ReplicatedStorage").CurrentCapturePoint.Value = "B"
game:GetService("ReplicatedStorage").NumOfCapturePoints.RedPoints.Value += 1
game:GetService("ReplicatedStorage").PointBeingCaptured:FireAllClients('A','Red',false,false)
script.Parent.BBG.Enabled = false
script.Parent.Parent.Parent.CapturePointB.CenterPiece.BBG.Enabled = true
elseif plr.TeamColor == BrickColor.new("Bright blue") and script.Parent.BrickColor ~= BrickColor.new("Bright blue") and script.Parent.ParticleEmitter.Enabled ~= true then
script.Parent.BrickColor = BrickColor.new("Bright blue")
game:GetService("ReplicatedStorage").PointBeingCaptured:FireAllClients('A','Blue',true)
script.Parent.ParticleEmitter.Enabled = true
script.Parent.ParticleEmitter.Color = ColorSequence.new(Color3.fromRGB(0,0,255))
wait(15)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
wait(.5)
script.Parent.ParticleEmitter.Size = NumberSequence.new(1)
wait(.5)
script.Parent.ParticleEmitter.Enabled = false
script.Parent.ParticleEmitter.Size = NumberSequence.new(.1)
game:GetService("ReplicatedStorage").CurrentCapturePoint.Value = "B"
game:GetService("ReplicatedStorage").NumOfCapturePoints.BluePoints.Value += 1
game:GetService("ReplicatedStorage").PointBeingCaptured:FireAllClients('A','Blue',false,false)
script.Parent.BBG.Enabled = false
script.Parent.Parent.Parent.CapturePointB.CenterPiece.BBG.Enabled = true
end
end
end
end)
LocalScript for the remote event:
game:GetService("ReplicatedStorage").PointBeingCaptured.OnClientEvent:Connect(function(point,Team,Started,CapturerDied)
if Started == true then
script.Parent.Frame.Warning.Visible = true
script.Parent.Frame.Warning.Text = "<font color='rgb(255,0,0)'>"..Team.."</font> is capturing the point <font color ='rgb(168,66,213)'>"..point.."</font>!"
else
if CapturerDied == false then
script.Parent.Frame.Warning.Text = "<font color='rgb(255,0,0)'>"..Team.."</font> has successfully captured the point <font color ='rgb(168,66,213)'>"..point.."</font>!"
wait(2)
script.Parent.Frame.Warning.Visible = false
else
script.Parent.Frame.Warning.Text = "<font color='rgb(255,0,0)'>"..Team.."</font> has failed in capturing the point <font color ='rgb(168,66,213)'>"..point.."</font>! Rest assured, they'll come back!"
wait(2)
script.Parent.Frame.Warning.Visible = false
end
end
end)
Thanks so much!