Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

for some reason a function I made isn't working, could someone tell me why isn't it working?

Hi so I was making a very small project to practice scripting, so the project is when you step on a part a ball changes colors, but when I try it, I touch the ball with my feet and it doesn't work . the ball is called discoball and the part is called button

here is the code:

local discoball = game.Workspace.discoball
local button = game.Workspace.button
function activatediscoball ()
	discoball.Material = Enum.Material.Neon
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
end

button.Touched:Connect(activatediscoball())

Thank you in advance

Edit: Now I have edited it into this:

local discoball = game.Workspace.discoball
local button = game.Workspace.button
button.Touched:Connect(function()
	discoball.Material = Enum.Material.Neon
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
	discoball.color = Color3.fromRGB(255, 0, 0)
	wait (0.25)
	discoball.color = Color3.fromRGB(0, 255, 0)
	wait (0.25)
	discoball.Color = Color3.fromRGB(0, 0, 255)
	wait (0.25)
end)

So after editing, I have put a bracket next to the end on the end, and have removed the event of touched and have put it on the beginning, i have removed the name of the function and have put in the brackets of the connect in the touched event, still doesnt work, it tells me in the output that color isn't a valid member of part Workspace.discoball

plz help

2 answers

✓ Accepted answer

Pretty hard to notice but you miscapitalized some of the words "Color" especially at the beginning.

Edit: Forgot to mention. Make sure to make it so that the player is allowed to touch it and not any other object. I'll add it to the scripts below.

Correct Script:

local discoball = game.Workspace.discoball
local button = game.Workspace.button
button.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        discoball.Material = Enum.Material.Neon
        discoball.Color = Color3.fromRGB(255, 0, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 255, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 0, 255)
        wait (0.25)
        discoball.Color = Color3.fromRGB(255, 0, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 255, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 0, 255)
        wait (0.25)
        discoball.Color = Color3.fromRGB(255, 0, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 255, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 0, 255)
        wait (0.25)
        discoball.Color = Color3.fromRGB(255, 0, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 255, 0)
        wait (0.25)
        discoball.Color = Color3.fromRGB(0, 0, 255)
        wait (0.25)
    end
end)

Shorter version:

local discoball = game.Workspace.discoball
local button = game.Workspace.button

button.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		discoball.Material = Enum.Material.Neon
		for i = 1,4 do
			discoball.Color = Color3.fromRGB(255, 0, 0)
			wait (0.25)
			discoball.Color = Color3.fromRGB(0, 255, 0)
			wait (0.25)
			discoball.Color = Color3.fromRGB(0, 0, 255)
			wait (0.25)
		end
	end
end)

1 comment

0

Thank You :)

I really think you should capitalize Color, that should help

local discoball = game.Workspace.discoball
local button = game.Workspace.button
button.Touched:Connect(function()
    discoball.Material = Enum.Material.Neon
    discoball.Color = Color3.fromRGB(255, 0, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 255, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 0, 255)
    wait (0.25)
    discoball.Color = Color3.fromRGB(255, 0, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 255, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 0, 255)
    wait (0.25)
    discoball.Color = Color3.fromRGB(255, 0, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 255, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 0, 255)
    wait (0.25)
    discoball.Color = Color3.fromRGB(255, 0, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 255, 0)
    wait (0.25)
    discoball.Color = Color3.fromRGB(0, 0, 255)
    wait (0.25)
end)

1 comment

0

Thank You :)

This discussion is preserved as it was. New answers, comments, and votes are closed.