Ball events not working

Hello, devforums!
This is a script that’s supposed to check if a ball is a type of color (red, yellow, orange), and if it is, it makes the ball catch on fire and also catches whoever it kills on fire.
The same should be for a green type of color for acid.
But it isn’t and I don’t know why.
Here’s the script:

local r = workspace.enemi.killr.scary.Color.R
local g = workspace.enemi.killr.scary.Color.G
local b = workspace.enemi.killr.scary.Color.B

if tonumber(r) <= 255 and tonumber(g) <= 204 and tonumber(b) <= 0 then
	local fire = Instance.new("Fire")
	fire.Parent = script.Parent
	fire.Size = 5
	fire.Heat = 20
	fire.Color = Color3.fromRGB(r, g, b)
	print("Fire started")
	local child = game.Workspace:GetChildren()
	if child:IsA("ragdoll") then
		local hdf = Instance.new("Fire")
		hdf.Parent = child.Torso
		hdf.Size = 5
		hdf.Heat = 20
		hdf.Color = Color3.fromRGB(r, g, b)
	end
	if tonumber(r) <= 1 and tonumber(g) <= 255 and tonumber(b) <= 193 then
		fire:Destroy()
		print("fire's out")
		local par = Instance.new("ParticleEmitter")
		par.Parent = script.Parent
		par.Color=Color3.fromRGB(37,255,106)
		par.Lifetime=1.25
		par.Rate=35
		print("aciddd")
	end
end

Thanks for every reply!

1 Like

Is there any errors in output and when it stop work?

1 Like

you are missing an end before the second conditional if!

after adding it, it should work fine.

...
   end
end --MISSING END!
if tonumber(r) <= 1 and tonumber(g) <= 255 and tonumber(b) <= 193 then
...

I don’t think that’s the issue, the person seems to have all the necessary ends in their script.

741125bff2b33c9cfb12bc781e073e68
at the bottom of the image, that isn’t just accidental indentation. That is misplacing an End, Which was mistakenly moved to the bottom.

i think you need to use elseif and put all ends to the end like this

local r = workspace.enemi.killr.scary.Color.R
local g = workspace.enemi.killr.scary.Color.G
local b = workspace.enemi.killr.scary.Color.B

if tonumber(r) <= 255 and tonumber(g) <= 204 and tonumber(b) <= 0 then
	local fire = Instance.new("Fire")
	fire.Parent = script.Parent
	fire.Size = 5
	fire.Heat = 20
	fire.Color = Color3.fromRGB(r, g, b)
	print("Fire started")
	local child = game.Workspace:GetChildren()
	if child:IsA("ragdoll") then
		local hdf = Instance.new("Fire")
		hdf.Parent = child.Torso
		hdf.Size = 5
		hdf.Heat = 20
		hdf.Color = Color3.fromRGB(r, g, b)
	
	elseif tonumber(r) <= 1 and tonumber(g) <= 255 and tonumber(b) <= 193 then
		fire:Destroy()
		print("fire's out")
		local par = Instance.new("ParticleEmitter")
		par.Parent = script.Parent
		par.Color=Color3.fromRGB(37,255,106)
		par.Lifetime=1.25
		par.Rate=35
		print("aciddd")
      end
	end
end

1 Like

The issue with this script is that it is only checking the color values once, when the script is first run. It does not have any kind of loop or event that constantly checks the color of the ball. Additionally, the code to check for a green color is nested within the code that checks for a yellow/orange color, so it will never be reached.

To fix this, you can use a loop or an event that constantly checks the color of the ball. Here is an example of how you can do this:

local ball = workspace.enemi.killr.scary -- Assuming this is the ball you want to check

local function checkColor()
local color = ball.Color
if color == Color3.new(1, 0, 0) or color == Color3.new(1, 0.8, 0) or color == Color3.new(1, 0.5, 0) then
-- Ball is red, yellow, or orange
local fire = Instance.new("Fire")
fire.Parent = ball
fire.Size = 5
fire.Heat = 20
fire.Color = color
print("Fire started")

	for _, child in ipairs(game.Workspace:GetChildren()) do
		if child:IsA("Model") and child:FindFirstChild("Humanoid") then
			local hdf = Instance.new("Fire")
			hdf.Parent = child.HumanoidRootPart
			hdf.Size = 5
			hdf.Heat = 20
			hdf.Color = color
		end
	end
elseif color == Color3.new(0, 1, 0) then
	-- Ball is green
	local par = Instance.new("ParticleEmitter")
	par.Parent = ball
	par.Color=Color3.new(0.145, 1, 0.416)
	par.Lifetime=1.25
	par.Rate=35
	print("Acid!")
else
	-- Ball is not red, yellow, orange, or green
	return
end
end

-- Check the color of the ball every second
while wait(1) do
checkColor()
end

This code creates a function called checkColor() that checks the color of the ball every time it is called. It checks if the ball is red, yellow, or orange and creates a fire if it is. If the ball is green, it creates an acid particle effect. The loop at the end of the code continuously calls the checkColor() function every second to keep checking the color of the ball.

1 Like

No, it just doesn’t work.

charrrrr

Thank you for all the replies! :slight_smile:

One more question, can you also somehow make it so when it’s acid the fire destroys itself, and when it’s fire the acid destroys itself?
I’ve tried a bunch of times and it’s error after error.
By the way, thank you for the solution!

Try this

local ball = workspace.enemi.killr.scary -- Assuming this is the ball you want to check
local check = 0

local function checkColor()
local color = ball.Color
if color == Color3.new(1, 0, 0) or color == Color3.new(1, 0.8, 0) or color == Color3.new(1, 0.5, 0) then
-- Ball is red, yellow, or orange
local fire = Instance.new("Fire")
fire.Parent = ball
fire.Size = 5
fire.Heat = 20
fire.Color = color
fire.Name= "Fire"
check = 1
print("Fire started")

	for _, child in ipairs(game.Workspace:GetChildren()) do
		if child:IsA("Model") and child:FindFirstChild("Humanoid") then
			local hdf = Instance.new("Fire")
			hdf.Parent = child.HumanoidRootPart
			hdf.Size = 5
			hdf.Heat = 20
			hdf.Color = color
		end
	end
elseif color == Color3.new(0, 1, 0) then
	-- Ball is green
	local par = Instance.new("ParticleEmitter")
	par.Parent = ball
	par.Color=Color3.new(0.145, 1, 0.416)
	par.Lifetime=1.25
	par.Rate=35
    par.Name ="Acid"
    check = 2
	print("Acid!")
else
	-- Ball is not red, yellow, orange, or green
	return
end
end

-- Check the color of the ball every second
while wait(1) do
checkColor()
if check == 1 then
ball:FindFirstChild("Acid"):Destroy()
elseif check == 2 then
ball:FindFirstChild("Fire"):Destroy()
  end
end
1 Like

It doesn’t work, thanks for the try!

Try this:

local ball = workspace.enemi.killr.scary -- Assuming this is the ball you want to check
local check = 0

local function checkColor()
local color = ball.Color
if color == Color3.new(1, 0, 0) or color == Color3.new(1, 0.8, 0) or color == Color3.new(1, 0.5, 0) then
-- Ball is red, yellow, or orange
local fire = Instance.new("Fire")
fire.Parent = ball
fire.Size = 5
fire.Heat = 20
fire.Color = color
fire.Name= "Fire"
check = 1
print("Fire started")

	for _, child in ipairs(game.Workspace:GetChildren()) do
		if child:IsA("Model") and child:FindFirstChild("Humanoid") then
			local hdf = Instance.new("Fire")
			hdf.Parent = child.HumanoidRootPart
			hdf.Size = 5
			hdf.Heat = 20
			hdf.Color = color
		end
	end
elseif color == Color3.new(0, 1, 0) then
	-- Ball is green
	local par = Instance.new("ParticleEmitter")
	par.Parent = ball
	par.Color=Color3.new(0.145, 1, 0.416)
	par.Lifetime=1.25
	par.Rate=35
    par.Name ="Acid"
    check = 2
	print("Acid!")
else
	-- Ball is not red, yellow, orange, or green
	return
end
end

-- Check the color of the ball every second
while wait(1) do
if check == 1 then
local Acid = ball:FindFirstChild("Acid")
   if Acid == not nil then 
     Acid:Destroy()
end
elseif check == 2 then
local Fire = ball:FindFirstChild("Fire")
  if Fire == not nil then
  Fire:Destroy()
    end
  end
checkColor()
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.