How to vibrate / shake a player?

Basically i want to make a player shake / vibrate, this is an example of how i want to do it:

https://gyazo.com/3d9cf768fadfe8202e1629082f156e7c

I just need to make it so it’s toggable, so i can start and stop it.

I would appreciate if someone could help me, thanks! :slightly_smiling_face:

You can do that with just move the position of the player

1 Like

Could you be more specific?

Should moving just one piece of the player work? For example the HumanoidRootPart

1 Like

Yes. Moving the root part will move all limbs due to welds.

2 Likes

Not sure if you know this but moving the root part of a character by changing its position breaks the welds and kills the player. You have to use cframes @Faczki.

EDIT: You could also make a custom idle animation and have that stutter back and forth. It would be easier.

1 Like

It’s the same thing. CFrames hold a vector3 and a rotation value.

Even though they are simmilar i don’t think they’re the same thing

No, Position and CFrame are different properties for a reason. Changing the root part’s Position property will kill the player. Changing the CFrame will not. Hence the function, :SetPrimaryPartCFrame()

1 Like

Even though i can easily make the player vibrate, how can i make it stop?

Well, you could do something like this to make them vibrate:

local player = game.Players.LocalPlayer
local char = player.Character
local hrp = player.Character:WaitForChild("HumanoidRootPart")

local isVibrating = false

someEvent:Connect(function()
   isVibrating = not isVibrating -- Toggles it
end)

while isVibrating do
   -- do something with the 'hrp' variable to make them shake.
   wait(.1)
end

Some event could be a keypress, etc.

I made this simple function which will run code constantly for the imputed time:

function RunForSeconds(seconds)
	local startTick = tick()
	while tick() <= startTick + seconds do
		-- CODE TO RUN FOR CERTAIN TIME
		wait(0.01) -- Cool down to prevent crash
	end
end

Would something like this work:

while isVibrating do
	hrp.CFrame = CFrame.new(hrp.CFrame + 0, 0,0, 1)
	wait(.1)
	hrp.CFrame = CFrame.new(hrp.CFrame - 0, 0,0, 1)
end

I believe it should. I’m not too experienced with CFrames though, so I am not sure.

I tried it out and it did not work. No errors on the output though :slightly_frowning_face:

Randomly generate a number between 0-0.1 studs and make the character move by that much.

The issue i’m having is the moving part, this is a script i tried that didn’t work:

try this one:

local Cframe = hrp.CFrame
while isVibrating do
   hrp.CFrame = hrp.CFrame * CFrame.new(1,0,0)
   wait(0.05)
   hrp.CFrame = Cframe
   wait(0.05)
   hrp.CFrame = hrp.CFrame * CFrame.new(-1,0,0)
   wait(0.05)
end

Still doesn’t, i’m starting to think that the problem is not at the moving part of the script.

Edit: Yes, i added a print to the script and it did not print anything

idk bro, maybe put “0.1” instead of “.1”

I just realized the problem wasn’t at the moving part and yet the other one.