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

How to make Click To Move the only movement mode?

Asked by 4 years ago

I think the title explains it quite well, I wish to force the user in the game to use ClickToMove , disabling the option to use the keyboard as well.

I tried to use the DevComputerMovementMode in the StarterPlayer properties but it has been more than useless.

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

Keep it at keyboard and mouse and Use this script. It will disable movement from keyboard and will have its own click to walk function! Make this a localscript named "ControlScript" in StarterPlayerScripts (Must be named "ControlScript" specificly the way it is currently)

repeat wait() until game.Players.LocalPlayer
Plr=game.Players.LocalPlayer
repeat wait() until Plr.PlayerScripts
repeat wait() until Plr.PlayerScripts.ControlScript
Plr.PlayerScripts.ControlScript:remove()
Mouse=Plr:GetMouse()
repeat wait() until Plr.Character
Char=Plr.Character

local Bin=Instance.new("Message")
Bin.Name="LocalBin" --Makes the part a 'LocalPart' so only you can see it.
Bin.Parent=Char
Hover=Instance.new("Part",Bin)
Hover.Name=Plr.Name.."'s Hover Block"
Hover.FormFactor="Custom"
Hover.Size=Vector3.new(3,.2,3)
Hover.CanCollide=false
Hover.Anchored=true
Hover.BrickColor=BrickColor.new("Lime green")
Mouse.TargetFilter=Hover
Mesh=Instance.new("CylinderMesh",Hover)

function HoverUpdate(Mouse) --Sets up function to update position
    if Mouse.Target then
        X=Mouse.Hit.X
        Y=Mouse.Hit.Y
        Z=Mouse.Hit.Z
        X2=Plr.Character.HumanoidRootPart.Position.X
        Y2=Plr.Character.HumanoidRootPart.Position.Y
        Z2=Plr.Character.HumanoidRootPart.Position.Z
        DisX=math.abs(X-X2)
        DisY=math.abs(Y-Y2)
        DisZ=math.abs(Z-Z2)
        Distance=DisX+DisY+DisZ
        if Distance<=100 then
            Hover.Position=Vector3.new(Mouse.Hit.X,Mouse.Hit.Y+.2,Mouse.Hit.Z)
            Hover.Transparency=0
        else
            Hover.Transparency=1
        end
    else
        Hover.Transparency=1
    end
end

Mouse.Move:connect(function() --Updates disc position
    PlrMouse=Plr:GetMouse()
    HoverUpdate(PlrMouse)
end)

Plr.Character.Torso.Changed:connect(function() --Updates disc position
    PlrMouse=Plr:GetMouse()
    HoverUpdate(PlrMouse)
end)

Mouse.Button1Down:connect(function() --Moves character to target position
    if Mouse.Target~=nil and Hover.Transparency==0 then
        Char.Humanoid.WalkToPoint=Hover.Position
    end
end)

Mouse.KeyDown:connect(function(Key) --Replication of 'Jump' button.
    if Key==" " then
        local Space=true
        repeat wait()
            Mouse.KeyUp:connect(function(Key)
                if Key==" " then
                    Space=false
                end
            end)
            Char.Humanoid.Jump=true
        until Space==false
    end
end)
0
Thank you so much for the help, I appreciate it. TheArtistTree 21 — 4y
0
So I know it has been a while but I just noticed it now. So when you reset your character, the click-to-move doesn't work anymore and you are stuck in place. TheArtistTree 21 — 4y
0
Then put it in startercharacterscripts so it resets when your player respawns! Lakodex 711 — 4y
0
Unfortunately not a fix to the issue. TheArtistTree 21 — 4y
Ad

Answer this question