im making a game where the killer has a trail they make on the ground that gives poison but when you get it and it goes away you don’t get it again.
local BloodP = script.Parent.BloodP
BloodP.CFrame = script.Parent.CFrame * CFrame.new(0, 2, 0)
BloodP.Touched:Connect(function(hit)
if hit.Name == "HumanoidRootPart" then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local buffs = player.PlayerGui.ScreenGui["Buffs/Debuffs"]
if not buffs:FindFirstChild("Poison") then
local Poison = game.ReplicatedStorage["Buff/Debuff"]:Clone()
Poison.Parent = buffs
Poison.Name = "Poison"
Poison.BDtext.Text = "Poison"
Poison.time.Value = 5
Poison.amount.Value = 1
end
end
end
end)
yes, the player touches it the second time but the effect doesn’t work, I’ve tested it and i think it might be the code kills itself or smth, the code works the first time its touched but right after the code kills itself and stops working.
I’ll add a bunch of prints. Can you send your output?
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)
print(hit.Name)
if hit.Name == "HumanoidRootPart" then
local playerName = hit.Parent.Name
print("Player name:", playerName)
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 then print("No 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
print(poisonSreenGUI)
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
print("Initialized Poison")
task.wait(5) -- I assume your "time" value is in seconds
print("Finished wait")
Poison:Destroy()
print("Destroyed, ", Poison, " should be nil")
end
end
end)
the “print(poisonSreenGUI)” prints nil all the time even when you have the effect.
it might not see the player having it. and the thing works after you lose the effect (I think) it just doesn’t give the effect anymore.
(it also thinks the player never has the effect)
(the code is in a server script too if that changes anything)
Oh, I think you/I may have confused the buffs ScreenGUI with the Poison GUI object. Try 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)
print(hit.Name)
if hit.Name == "HumanoidRootPart" then
local playerName = hit.Parent.Name
print("Player name:", playerName)
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 then print("No player") return end -- Make sure the player actually exists
local buffsScreenGUI = player.PlayerGui.ScreenGui["Buffs/Debuffs"] -- Set this as a variable, no need to follow this complex index chain multiple times
local defaultPoisonGUI = buffsScreenGUI:FindFirstChild("Poison")
local oldPoisonGUI = buffsScreenGUI:FindFirstChild("NewPoison")
print(oldPoisonGUI)
if not oldPoisonGUI then
print(player)
local Poison = defaultPoisonGUI:Clone()
Poison.Parent = buffsScreenGUI
Poison.Name = "NewPoison"
Poison.BDtext.Text = "Poison"
Poison.time.Value = 5
Poison.amount.Value = 1
print("Initialized Poison")
task.wait(5) -- I assume your "time" value is in seconds
print("Finished wait")
Poison:Destroy()
print("Destroyed, ", Poison, " should be nil")
end
end
end)
script.Parent.BloodP.CFrame = script.Parent.CFrame * CFrame.new(0, 2, 0)
script.Parent.BloodP.Touched:Connect(function(hit)
print(hit.Name)
if hit.Name == "HumanoidRootPart" then
local playerName = hit.Parent.Name
print("Player name:", playerName)
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 then print("No player") return end -- Make sure the player actually exists
local buffsScreenGUI = player.PlayerGui.ScreenGui["Buffs/Debuffs"]
local oldPoisonGUI = buffsScreenGUI:FindFirstChild("Poison")
print(oldPoisonGUI)
if not oldPoisonGUI then
print(player)
local defaultPoisonGUI = game.ReplicatedStorage["Buff/Debuff"]
local Poison = defaultPoisonGUI:Clone()
Poison.Parent = buffsScreenGUI
Poison.Name = "Poison"
Poison.BDtext.Text = "Poison"
Poison.time.Value = 5
Poison.amount.Value = 1
print("Initialized Poison")
task.wait(5) -- I assume your "time" value is in seconds
print("Finished wait")
Poison:Destroy()
print("Destroyed, ", Poison, " should be nil")
end
end
end)