Output: Attempt to connect failed: Passed value is not a function
Why is it saying that when it is a function, how can I fix it?
Thanks in advance.
Code:
local button = script.Parent local Cam = workspace.Camera local itemcam = workspace:WaitForChild("Shop").Cams.Cam local player = game.Players.LocalPlayer local PlayerGui = player:WaitForChild("PlayerGui") local Input = game:GetService("UserInputService") --- function OnClick() local ScreenGui = Instance.new("ScreenGui",PlayerGui) ScreenGui.Name = "Shop_Ui" local Frame = Instance.new("Frame",ScreenGui) local Buy_Button = Instance.new("TextButton",ScreenGui) Frame.Size = UDim2.new(0, 1920,0, 1079) Frame.Position = UDim2.new(0, 0,0, 0) Frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255) Frame.BackgroundTransparency = 1 Frame.BackgroundColor3 = Color3.fromRGB(255, 229, 124) --Fade for i = 1,20 do Frame.BackgroundTransparency = Frame.BackgroundTransparency -0.05 wait(0.01) end repeat wait() Cam.CameraType = Enum.CameraType.Scriptable until Cam.CameraType == Enum.CameraType.Scriptable Cam.CFrame = itemcam.CFrame wait(0.5) for i = 1,20 do Frame.BackgroundTransparency = Frame.BackgroundTransparency +0.05 wait(0.01) end local Buy_Button = Instance.new("TextButton",ScreenGui) Buy_Button.Name = "Buy_Button" Buy_Button.Font = Enum.Font.Cartoon Buy_Button.TextScaled = true Buy_Button.Text = "Buy" Buy_Button.BorderSizePixel = 3 Buy_Button.BorderColor3 = Color3.fromRGB(255,255,255) if Input.TouchEnabled == true then --Player On Phone Buy_Button.Size = UDim2.new(0, 78,0, 30) Buy_Button.Position = UDim2.new(0.43, 0,0.841, 0) elseif Input.KeyboardEnabled == true then Buy_Button.Size = UDim2.new(0, 189,0, 65) Buy_Button.Position = UDim2.new(0.5, 0,0.895, 0) function OnHover() button.ImageColor3 = Color3.fromRGB(255, 222, 121) for i = 1,5 do button.Rotation = button.Rotation +2 wait(0.01) end for i = 1,5 do button.Rotation = button.Rotation -2 wait(0.01) end for i = 1,5 do button.Rotation = button.Rotation +2 wait(0.01) end for i = 1,5 do button.Rotation = button.Rotation -2 wait(0.01) button.ImageColor3 = Color3.fromRGB(255, 255, 255) end end end end button.MouseEnter:Connect(OnHover) button.Activated:Connect(OnClick)
OnHover
is defined inside the code of OnClick (this is more obvious once the code is indented). It'll only get created if the function and elseif block it's in is ran. Before that, OnHover
is nil
.
To fix it, move the OnHover
definition out of the OnClick
function.