Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
Thank You :) Amazing_boy200912 5 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)
0
Thank You :) Amazing_boy200912 5 — 3y

Answer this question