local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
local swordHitbox = RaycastHitbox.new(script.Parent)
swordHitbox.OnHit:Connect(function(hit)
print("hit")
local model = hit.Parent
print(model.Name)
if model.Name == "Burger" or model.Name == "Taco" then
if model.ClassName == "Model" then
local health = model:GetAttribute("Health")
health = health-100
model:SetAttribute("Health", health)
end
end
end)
while true do
swordHitbox:HitStart()
wait(3)
swordHitbox:HitStop()
wait(3)
end
My problem is that it doesn’t take away any health from the model. How do I fix this?
You need to write back the changed value with SetAttribute. health only contains a copy of the value you’re trying to change, it doesn’t store the actual location of the Health attribute.
Can you think of anything else I might be doing wrong? I have all this code in a local script in the tool, not the part. After looking at the API, I edited the code a bit too. Here’s the new code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
print("Raycast Hitbox Module Found")
local swordHitbox = RaycastHitbox.new(script.Parent)
print("sword hitbox found")
swordHitbox.OnHit:Connect(function(hit, humanoid)
print("hit")
if not humanoid then
local model = hit.Parent
print(model.Name)
local health = model:GetAttribute("Health")
health = health-100
model:SetAttribute("Health", health)
print(health)
end
end)
script.Parent.Activated:Connect(function()
swordHitbox:HitStart()
wait(3)
swordHitbox:HitStop()
end)