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

I can't "Connect" my function it says passed value is not a function when it is why??

Asked by 5 years ago
Edited 5 years ago

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)
1
CODE BLOCK EVERYTHING Gameplayer365247v2 1055 — 5y
0
I'm such an idiot i forgot lol. Freddan2006YT 88 — 5y
0
REEEEEEEEEEEEEEEEEEEEEEEE indent your code BashGuy10 384 — 5y
0
After one year i still don't know how to indent my code.. Could you send a link of a tutorial or somthing. @BashGuy10 Freddan2006YT 88 — 5y

1 answer

Log in to vote
1
Answered by
Sulfone 141
5 years ago

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.

0
Thank you so much i would never had figured it out myself. Freddan2006YT 88 — 5y
Ad

Answer this question