I am once again looking to the Roblox Studio Forums for help. This time I made this script for a “kill brick” that will simply damage the player and then give them a tag that prevents them from taking damage for a short while. This is meant to replicate a health system similar to games like Mario where the health bar is segmented. I’ve tried looking online for resources or similar issues which led me to find out about tags, but the script is still buggy. As far as I know, the tags are given to the player but the block doesn’t do damage even if the player doesn’t have the tag. My script is below. I’ve labeled it with comments so you can get a feel for what I am trying to do
local damage = 20
local CS = game:GetService("CollectionService")
local tag = "iframes"
local function damage(otherPart) -- Checks if the object is a player
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChild("Humanoid")
if humanoid then
if not CS:HasTag(partParent, tag) then -- Checks if the player has the iframes tag. If it does not, the player takes damage
humanoid.Health = humanoid.Health - damage
CS:AddTag(partParent, tag)
wait(1) -- The player has iframes for 1 second after being damaged
CS:RemoveTag(partParent, tag)
end
end
end
script.Parent.Touched:Connect(damage) -- The fuction is called on touch
If you need more information please let me know.