Following my last question, thats been answered, I've joined 2 scripts so when the cannon ball hits the boat, it explodes, and takes 20 away from the int value. Now it had been working for a while, but when i turned, on line 47, math.random(1,3), into true, it has stopped decreasing. I'm pretty sure its a small error, but nothings coming out in the console. So can you guys please help identifying the problem?
ball = script.Parent
damage = 50
local debounce = true
function onTouched(hit)
local RESET_SECONDS = 5
local isTouched = false
ball.Touched:Connect(function(part)
if isTouched then return end
local car = ball:FindFirstAncestor("car")
local value = if car then car:FindFirstChild("Int", true) else nil
if not value then return end
isTouched = true
value.Value -= 20
wait(RESET_SECONDS)
isTouched = false
end)
local humanoid = hit.Parent:findFirstChild("Humanoid")
if humanoid~=nil then
tagHumanoid(humanoid)
humanoid.Health = humanoid.Health - damage
if debounce then
debounce = false
if humanoid.Health == 0 or humanoid.Health < 0 then
local z = game.Players:FindFirstChild(game.ReplicatedStorage.asd.Value)
z.leaderstats.Kills.Value += 1
wait(2)
debounce = true
end
end
untagHumanoid(humanoid)
else
damage = damage / 2
if damage < 2 then
ball.Parent = nil
end
end
if true then
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 9
explosion.BlastPressure = 1000000 -- these are really wussy units
explosion.Position = script.Parent.Position
explosion.Parent = game.Workspace
connection:disconnect()
ball.Parent = nil
end
end
function tagHumanoid(humanoid)
-- todo: make tag expire
local tag = ball:findFirstChild("creator")
if tag ~= nil then
local new_tag = tag:clone()
new_tag.Parent = humanoid
end
end
function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
connection = ball.Touched:connect(onTouched)
r = game:service("RunService")
t, s = r.Stepped:wait()
d = t + 5.0 - s
while t < d do
t = r.Stepped:wait()
end
ball.Parent = nil

4 comments
oh god, the last part looks like something TheeDeathCaster makes.
... So whats wrong tho
On line 47, you aren't specifying an object/value to check if it's true. You need to call an object before checking if any of it's properties are true because the game doesn't know what to check.
If i do if true then, that means the statement is always true. So...