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

Why will my player not move and how do I make it follow the mouse?

Asked by
joeldes 201 Moderation Voter
7 years ago

Hello, I am new to the community here. I have been recently been working on a game where I have a sphere that is the player. I made it so that you could view the player from perfect top down. Unfortunately, when I did this the player stopped moving with WASD keys. I noticed that as soon as I change the Vector3 to not point the CFrame all the way down the character moves again but in a diagonal and inverted way.

Here's my code:

01print("Intalized Camera Script")
02 
03local RunService = game:GetService("RunService")
04local Players = game:GetService("Players")
05 
06local OFFSET = Vector3.new(0, 400, 0)
07local FOV = 30
08 
09local player = Players.LocalPlayer
10local camera = game.Workspace.CurrentCamera
11 
12camera.FieldOfView = FOV
13 
14local function onRenderStep()
15    local character = player.Character
View all 26 lines...

I followed the Roblox Wiki tutorial and modified it to fit my needs. I have been searching for hours for answers. Maybe I am blind and can't read or I am finding nothing.

Basically I need help composing a script that will allow my player to move by following the direction the mouse is pointing on the screen. I am trying to keep my view to be perfectly looking straight down.

Please note that I am new to Lua completely and am not looking to be spoon fed the script. But please be as detailed as possible so I can learn :D.

Thanks!

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

This script will just automatically move the character towards the mouse, if that’s what you are looking for.

1local mouse = game.Players.LocalPlayer:GetMouse()
2mouse.Move:Connect(function()
3    game.Players.LocalPlayer.Character.Humanoid:MoveTo(mouse.Hit.p)
4end)
0
Thank you so much. That works! But for some reason it only works in the studio and not as a published game joeldes 201 — 7y
0
You should put this in a local script inside StarterGui or somewhere else that is individual to each player. mattscy 3725 — 7y
Ad

Answer this question