Make an object move using player's directional buttons

yes, i’m doing it because the fish will be ragdolled and the humanoidrootpart wont move

If the fish is rag dolled, how it is supposed to move? (might be a stupid question)

this is why i created this post: the part i’m trying to make move is the fish’ torso and i want the player to be able to move it by clicking the normal roblox controlling buttons

Okay. Why don’t you create a StarterCharacter?

i did but the humanoidrootpart stands up so it doesn’t let the fish actually be ragdolled

Rotate everything but the root part by 90 degrees.

but then if the fish jumps it can only land on 1 side

maybe change the y to the part CFrame’s Y coordinate?

part.CFrame = CFrame.new(Vector3.new(x, part.CFrame.Y, z),Vector3.new(x + (directions.d - directions.a), part.CFrame.Y, z + (directions.w - directions.s)))

sorry where do i put this? im so bad haha

Here is the full script that is updated with the change.

part = -- change this to the part
speed = 1 -- change this to make part slower or faster
halt = 1 -- change this to make part halt less. Decreasing this will lower performance, while increasing this will make this less realistic

directions = {w = 0, a = 0, d = 0, s = 0} -- when a button gets pressed, make it 1

while true do
	local z = part.CFrame.z
	local x = part.CFrame.x

	x += ((directions.d - directions.a) * speed) / ((directions.w - directions.s) * (directions.w - directions.s))
	z += ((directions.w - directions.s) * speed) / ((directions.d - directions.a) * (directions.d - directions.a))	
    part.CFrame = CFrame.new(Vector3.new(x, part.CFrame.Y, z),Vector3.new(x + (directions.d - directions.a), part.CFrame.Y, z + (directions.w - directions.s)))
	wait(halt) -- 
end

is this a local or server script? where should i put it?

well, both really. You would need another script to detect when a ui/gui button is pressed and then another one to move it, which is this one. You can use a RemoteEvent to do this. You can put it wherever, really. But, I would recommend putting it where the remote event is.

oh but there is no gui. wit directional buttons i ment the ones on the keyboard

Oh, ok. That is easier in this case. Put the local script under the same instance as the server script (note it has to be in some kind of starter player folder) and do this:

-- local script

game.UserInputService.InputBegan:Connect(function(inputObject,isTyping)
	if isTyping then return end
	script.Parent.RemoteEvent:FireServer(inputObject.KeyCode,1)	
end)

game.UserInputService.InputEnded:Connect(function(inputObject,isTyping)
	if isTyping then return end
	script.Parent.RemoteEvent:FireServer(inputObject.KeyCode,0)	
end)


-- server script (the one above)

part = -- change this to the part
speed = 1 -- change this to make part slower or faster
halt = 1 -- change this to make part halt less. Decreasing this will lower performance, while increasing this will make this less realistic

directions = {w = 0, a = 0, d = 0, s = 0} -- when a button gets pressed, make it 1

script.Parent.RemoteEvent.OnServerEvent:Connect(function(keycode,value)
    if keycode == Enum.KeyCode.W then
	directions.w = value
    end
    if keycode == Enum.KeyCode.D then
	directions.d = value
    end
    if keycode == Enum.KeyCode.A then
	directions.a = value
    end
    if keycode == Enum.KeyCode.S then
	directions.s = value
    end
end)

while true do
	local z = part.CFrame.z
	local x = part.CFrame.x

	x += ((directions.d - directions.a) * speed) / ((directions.w - directions.s) * (directions.w - directions.s))
	z += ((directions.w - directions.s) * speed) / ((directions.d - directions.a) * (directions.d - directions.a))	
    part.CFrame = CFrame.new(Vector3.new(x, part.CFrame.Y, z),Vector3.new(x + (directions.d - directions.a), part.CFrame.Y, z + (directions.w - directions.s)))
	wait(halt) -- 
end

i put them both inside of starterplayerscripts, is it okay? also, there are a couple errors with () and i dont want to mess up

K, I edited the local script part, but starterPlayerScripts has an issue with server scripts. To fix this, put it in starter character scripts.

Screenshot 2024-01-22 alle 02.11.15

I fixed the error on top, but what does it say when you go over halt?

Ohh, it is because of the error above. I fixed the error above once I realized I made that mistake.