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

How to fix move script?

Asked by 9 years ago

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...

0
May I suggest using BodyVelocity. magiccube3 115 — 9y
0
What you mean in using BodyVelocity? i think it works only on parts. DevKarolus1 70 — 9y

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

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)
0
So can you tell me how? DevKarolus1 70 — 9y
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 Validark 1580 — 9y
0
When you destroy controlscirpt you can't move ;/ DevKarolus1 70 — 9y
0
If you are moving when it is destroyed, you will keep walking. Validark 1580 — 9y
0
So can you write answear and tell me where i should add? DevKarolus1 70 — 9y
Ad

Answer this question