Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use m.Move:connect() then correctly?

so Im trying to lerp a block to my current mouse position but I receive the error Attempt to connect failed: Passed value is not a function at the if m.Move:connect() then.

spawn(function()
	local m = game.Players.LocalPlayer:GetMouse()
	if m.Move:Connect() then
for i = 1, #SoundBlok do
    if i == 1 then
      SoundBlok[i].CFrame = SoundBlok[i].CFrame:lerp(m.Hit, 0.1)
    end
  end
for i = 1, #SoundBlok2 do
    if i == 1 then
      SoundBlok2[i].CFrame = SoundBlok2[i].CFrame:lerp(m.Hit, 0.1)
    end
  end
	end
end)
end)

This works but the errors slowly cause your game to lag out and eventually freeze

How would I go about fixing this? I've tried many things

1 comment

0

Your problem is line 3: You tried to create a function in the if statement. XP To fix this, just rewrite it as a function + event duo, or anonymous function. :) Also, I would recommend putting waits in the for loops to prevent that "lag," if that's what's causing that.

1 answer

✓ Accepted answer
spawn(function()
    local m = game.Players.LocalPlayer:GetMouse()
    m.Move:connect(function()
for i = 1, #SoundBlok do
    if i == 1 then
      SoundBlok[i].CFrame = SoundBlok[i].CFrame:lerp(m.Hit, 0.1)
    end
  end
for i = 1, #SoundBlok2 do
    if i == 1 then
      SoundBlok2[i].CFrame = SoundBlok2[i].CFrame:lerp(m.Hit, 0.1)
    end
  end
    end
end)
end)

Try this it may not be 100% right cus i wrote it in da browser

2 comments

0

It works but now it doesnt lerp

0

What was the reasoning behind your answer? What was wrong with the original? Dude, don't just post code: doesn't help anyone. ;/

This discussion is preserved as it was. New answers, comments, and votes are closed.