CodeStuff
CodeStuff

Reputation: 1

Attempted to call a nil value

local Ball = game.Workspace.Ball --Define the object we will clone.

local function OnEnter() --When mouse enters the button, the button will change color.
    Button.BorderColor = Color3.new(0.454902, 0.454902, 0.454902)
end

local function OnExit() --When the mouse exits the button will return to normal.
    Button.BorderColor = Color3.new(1, 1, 1)
end

local function OnClick() -- When the mouse clicks on the button, the ball is cloned
    local NewBall = Ball:Clone()
    NewBall.Position = Vector3.new(248.027, 69.405, -216.25)
end

Button.MouseButton1Up:Connect(OnClick()) -- Connecting the functions above to their events
Button.MouseEnter:Connect(OnEnter())
Button.MouseLeave:Connect(OnExit())

The Enter and exit functions are working, so I know that it is the Ball:Clone() that isn`t working. When I press the button, I get this error: "Attempted to call a nil value" Please help.

Upvotes: 0

Views: 538

Answers (1)

drantini
drantini

Reputation: 11

Either the game.Workspace.Ball is nil (therefore doesn't exist) or the game.Workspace.Ball does not have function Clone()

I suggest you read through roblox lua documentation and find if what i mentioned exists.

Upvotes: 1

Related Questions