So, it seems that this only happens in online mode, the problem is, every time you fire the bullet, it says that crit, mind, and maxd are not valid members of the script. It works if I add a wait, but then you have to fire from a far distance, or else the bullet does nothing.
ball = script.Parent --The bullet
crit = script.Crit.Value -- A value inside the script
mind = script.MinDMG.Value -- Same as above
maxd = script.MaxDMG.Value -- Same-o
damage = math.random(mind,maxd)
if script.Effect.Value == 1 then
clonedth = script.Effect.Fire:Clone()
clonedth.Enabled = true
clonedth.Parent = ball
elseif script.Effect.Value == 2 then
clonedth = script.Effect.Cor:Clone()
clonedth.Enabled = true
clonedth.Parent = ball
elseif script.Effect.Value == 3 then
clonedth = script.Effect.Spark:Clone()
clonedth.Enabled = true
clonedth.Parent = ball
end
function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild("HP")
local shield = hit.Parent:FindFirstChild("SP")
if shield ~= nil and shield.Value > 0 then
tagHumanoid(shield)
if hit.Name == "Head" then
shield.Value = shield.Value - damage * crit
elseif hit.Name == "Torso" then
shield.Value = shield.Value - damage * 1.1
if script["Effect"].Value == 1 then
local chance = math.random(1,2)
if chance == 1 then
local clonedth2 = script["Effect"].Fire2:Clone()
clonedth2.Enabled = true
clonedth2.Parent = hit
for i = 1, 10 do
wait(0.5)
shield.Value = shield.Value - damage / 7.5
end
clonedth2:Destroy()
end
elseif script["Effect"].Value == 2 then
local chance = math.random(1,2)
if chance == 1 then
local clonedth2 = script["Effect"].Cor2:Clone()
clonedth2.Enabled = true
clonedth2.Parent = hit
for i = 1, 10 do
wait(0.5)
shield.Value = shield.Value - damage / 2
end
clonedth2:Destroy()
end
elseif script["Effect"].Value == 3 then
local chance = math.random(1,2)
if chance == 1 then
local clonedth2 = script["Effect"].Spark:Clone()
clonedth2.Enabled = true
clonedth2.Parent = hit
for i = 1, 10 do
wait(0.5)
shield.Value = shield.Value - damage / 7.5
end
clonedth2:Destroy()
end
end
else
shield.Value = shield.Value - damage
end
connection:disconnect()
ball.Parent = nil
elseif humanoid ~= nil then
tagHumanoid(humanoid)
if hit.Name == "Head" then
humanoid.Value = humanoid.Value - damage * crit
elseif hit.Name == "Torso" then
humanoid.Value = humanoid.Value - damage * 1.1
if script["Effect"].Value == 1 then
local chance = math.random(1,2)
if chance == 1 then
local clonedth2 = script["Effect"].Fire2:Clone()
clonedth2.Enabled = true
clonedth2.Parent = hit
for i = 1, 10 do
wait(0.5)
humanoid.Value = humanoid.Value - damage / 5
end
clonedth2:Destroy()
end
elseif script["Effect"].Value == 2 then
local chance = math.random(1,2)
if chance == 1 then
local clonedth2 = script["Effect"].Cor2:Clone()
clonedth2.Enabled = true
clonedth2.Parent = hit
for i = 1, 10 do
wait(0.5)
humanoid.Value = humanoid.Value - damage / 7.5
end
clonedth2:Destroy()
end
elseif script["Effect"].Value == 3 then
local chance = math.random(1,2)
if chance == 1 then
local clonedth2 = script["Effect"].Spark:Clone()
clonedth2.Enabled = true
clonedth2.Parent = hit
for i = 1, 10 do
wait(0.5)
humanoid.Value = humanoid.Value - damage / 7.5
end
clonedth2:Destroy()
end
end
else
humanoid.Value = humanoid.Value - damage
end
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)
wait(8)
ball.Parent = nil
