I am trying to make an effect system and im trying to make it check for if the effect is already on the player and if it is then it doesn’t add it.
script.Parent.BloodP.CFrame = script.Parent.CFrame * CFrame.new(0, 2, 0)
while true do
wait(0)
script.Parent.BloodP.Touched:Connect(function(hit)
if hit.Name == "HumanoidRootPart" then
local player = hit.Parent.Name
if game.Players:FindFirstChild(player).PlayerGui.ScreenGui["Buffs/Debuffs"]:FindFirstChild("Poison") then
else
print(player)
local Poison = game.ReplicatedStorage["Buff/Debuff"]:Clone()
Poison.Parent = game.Players:FindFirstChild(player).PlayerGui.ScreenGui["Buffs/Debuffs"]
Poison.Name = "Poison"
Poison.BDtext.Text = "Poison"
Poison.time.Value = 5
Poison.amount.Value = 1
end
end
end)
end
it adds it the first time but when the effect ends you can’t get it again.
Well, as @Oceanblue857 said, you never remove the poison so it will always exist the second time. I assume you want to do this:
script.Parent.BloodP.CFrame = script.Parent.CFrame * CFrame.new(0, 2, 0)
-- Please DO NOT put a .Touched connection in a while true do statement, that's gonna become an insane memory leak
script.Parent.BloodP.Touched:Connect(function(hit)
if hit.Name == "HumanoidRootPart" then
local playerName = hit.Parent.Name
local player = game.Players:FindFirstChild(playerName) -- Ideally, you should create a "Players" variable at the start of your code with game:GetService()
if not player return end -- Make sure the player actually exists
local poisonScreenGUI = player.PlayerGui.ScreenGui["Buffs/Debuffs"]:FindFirstChild("Poison") -- Set this as a variable, no need to follow this complex index chain multiple times
if not poisonScreenGUI then
print(player)
local Poison = game.ReplicatedStorage["Buff/Debuff"]:Clone() -- Again, for good code readability, you should really create a variable at the start of your code for ReplicatedStorage
Poison.Parent = poisonScreenGUI
Poison.Name = "Poison"
Poison.BDtext.Text = "Poison"
Poison.time.Value = 5
Poison.amount.Value = 1
task.wait(5) -- I assume your "time" value is in seconds
Poison:Destroy()
end
end
end)
I also edited some stuff because it can be rewritten more cleanly and for better optimization.
local db = false
script.Parent.BloodP.CFrame = script.Parent.CFrame * CFrame.new(0, 2, 0)
while true do
wait(0)
script.Parent.BloodP.Touched:Connect(function(hit)
if db then return end
if hit.Name == "HumanoidRootPart" then
local player = hit.Parent.Name
if game.Players:FindFirstChild(player).PlayerGui.ScreenGui["Buffs/Debuffs"]:FindFirstChild("Poison") then
else
print(player)
local Poison = game.ReplicatedStorage["Buff/Debuff"]:Clone()
Poison.Parent = game.Players:FindFirstChild(player).PlayerGui.ScreenGui["Buffs/Debuffs"]
Poison.Name = "Poison"
Poison.BDtext.Text = "Poison"
Poison.time.Value = 5
Poison.amount.Value = 1
end
db = true
end
end)
end