by selecting a tool, this script moves the warrior (line 2) even though it makes him go to the edge of the map and fall off (that is a problem also)
how could i make this work by just clicking the mouse on the baseplate with no tool selected?
tool = script.Parent warrior = game.Workspace.Warrior playerMouse = game.Players.LocalPlayer:GetMouse() tool.Equipped:connect(function(m) m.Icon = "http://www.roblox.com/asset/?id=79658449" m.Move:connect(function() print("X Mouse Position: "..playerMouse.X.."",", ","Y Mouse Position: "..playerMouse.Y.."") warrior.Humanoid:MoveTo(Vector3.new(playerMouse.X,playerMouse.Y)) end) end)
i tried playerMouse:connect(click) it didnt even budge the warrior except with cframe and preset numbers
thanks to all that help me :)
Your function, "playerMouse:connect(click)" is wrong. Here, I will give you a short mouse tutorial.
First of all, make sure this is a LocalScript. Also, you should define the player. It's not needed, but you never know;
local player=game.Players.LocalPlayer --Get the player (local script only!)
Getting the Mouse is fairly similar;
local player=game.Players.LocalPlayer --Get the player local mouse=player:GetMouse() --Get the mouse
Now, the mouse has many properties and events. The event you need is Button1Down;
local player=game.Players.LocalPlayer --Get the player local mouse=player:GetMouse() --Get the mouse mouse.Button1Down:connect(function() --When the player clicks.. print("Left Mouse Button Clicked!") end)
The mouse also has a Hit property
that gets the Mouse's position;
local player=game.Players.LocalPlayer --Get the player local mouse=player:GetMouse() --Get the mouse mouse.Button1Down:connect(function() --When the player clicks.. print("Left Mouse Button Clicked!") print(mouse.Hit) --Prints the CFrame of the Mouse end)
Putting it all together
local player=game.Players.LocalPlayer --Get the player local mouse=player:GetMouse() --Get the mouse local warrior=workspace.Worrior--Get the warrior mouse.Button1Down:connect(function() --When the player clicks.. warrior.Humanoid:MoveTo((mouse.Hit).p) end)
Use the Button1Down
event of the mouse and connect it to a function.
tool = script.Parent warrior = game.Workspace.Warrior playerMouse = game.Players.LocalPlayer:GetMouse() tool.Equipped:connect(function(m) m.Icon = "http://www.roblox.com/asset/?id=79658449" m.Button1Down:connect(function() print("X Mouse Position: "..playerMouse.X.."",", ","Y Mouse Position: "..playerMouse.Y.."") warrior.Humanoid:MoveTo(Vector3.new(playerMouse.X,playerMouse.Y)) end) end)
Good Luck!