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

How Do I Invoke Events From A LocalScript to Be Read by Another LocalScript?

Asked by
RoboZB 2
4 years ago

Hey,

So I was making a loading menu for my game and I was trying to make a loading screen that when you clicked "Play" the camera unblurred and you could load into the game. However, I am getting the error:

OnInvoke is a callback member of BindableFunction; you can only set the callback value, get is not available

My camera script goes like this:

local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
local cam = workspace.CurrentCamera
local blur = Instance.new("BlurEffect",cam)
blur.Enabled = true
blur.Size = 2500
cam.CameraSubject = workspace:WaitForChild("CameraPart")
cam.CameraType = Enum.CameraType.Follow

script.Parent:WaitForChild("Load").OnInvoke:Connect(function()
    if game:GetService("RunService"):IsStudio() then print("Received!") end
    repeat
        wait(.1)
        blur.Size = blur.Size - 10
    until blur.Size <= 0
    script.Parent:Destroy()
end)

The button-handling script goes like this:

local play = script.Parent:WaitForChild("play")
local switch = script.Parent:WaitForChild("switch")
local event = script.Parent.Parent:WaitForChild("Load")


play.MouseButton1Click:Connect(function()
    script.Parent.Visible = false
    script.Parent.Parent.Load:Invoke()
    if game:GetService("RunService"):IsStudio() then print("Sent!") end
end)

I'm not really sure what I should do.

INFO: The switch code is because my game has multiple different versions.

Thanks in advance,

RoboZB

1 answer

Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

You did the OnInvoke wrong you need to set the callback like this:

local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
local cam = workspace.CurrentCamera
local blur = Instance.new("BlurEffect",cam)
blur.Enabled = true
blur.Size = 2500
cam.CameraSubject = workspace:WaitForChild("CameraPart")
cam.CameraType = Enum.CameraType.Follow

script.Parent:WaitForChild("Load").OnInvoke = function() --Fixed line.
    if game:GetService("RunService"):IsStudio() then print("Received!") end
    repeat
        wait(.1)
        blur.Size = blur.Size - 10
    until blur.Size <= 0
    script.Parent:Destroy()
end --Remember to remove this ")"
0
Can you tell me why you downvoted my answer? firestarroblox123 440 — 4y
0
I didn't. RoboZB 2 — 4y
0
Oh, im guessing a random person downvoted my answer. firestarroblox123 440 — 4y
Ad

Answer this question