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

How to fix move script?

Hello, I want to make a script, when player touch part then he can't stop. I mean he will still moving forward.

Here is my code, maybe will help something:

local m = game.Players:GetPlayerFromCharacter(script.Parent):GetMouse()
local p = 0
local r = false

function onTouch()
	coroutine.resume(coroutine.create(function()
m.KeyDown:connect(function(key)
if key:lower() == "w" then p = p + 0
delay(0.5,function()
if p ~= 0 then p = 0 end
end)
if p == 0 then p = 0
r = true
m.KeyUp:connect(function(key)
if key:lower() == "w" then r = false end
end) end end end) end ))

end

script.Parent.Touched:connect(onTouch)

I'm beginner scripter, so i still don't understand a lot...

2 comments

0

May I suggest using BodyVelocity.

0

What you mean in using BodyVelocity? i think it works only on parts.

1 answer

A better solution would be to remove PlayerScripts.ControlScript, this will make them keep walking and they will not be able to stop.

Here's an easier-to-read version of your code:

local m = game.Players:GetPlayerFromCharacter(script.Parent):GetMouse()
local p = 0
local r = false

function onTouch()
	coroutine.resume(coroutine.create(function()
		m.KeyDown:connect(function(key)
			if key:lower() == "w" then
				p = p + 0
				delay(0.5, function()
					if p ~= 0 then
						p = 0
					end
				end)
				if p == 0 then
					p = 0
					r = true
					m.KeyUp:connect(function(key)
						if key:lower() == "w" then
							r = false
						end
					end)
				end
			end
		end)
	end ))

end

script.Parent.Touched:connect(onTouch)

5 comments

0

So can you tell me how?

0

local controlScript = game.Players.LocalPlayer.PlayerScripts.ControlScript:Clone(); game.Players.LocalPlayer.PlayerScripts.ControlScript:Destroy(); --Parent the clone back to LocalPlayer once they get control back

0

When you destroy controlscirpt you can't move ;/

0

If you are moving when it is destroyed, you will keep walking.

0

So can you write answear and tell me where i should add?

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