Hello! I’m making a SWAT game where you play as a commander from above.
The SWAT units are controlled by clicking them then clicking where you want to go.
I am puzzled by this and only understand the Humanoid:MoveTo(), the getmouse from local player
And that’s all.
Try something like this:
(local script)
local mouse = game.Players.LocalPlayer:GetMouse()
local db = false
mouse.Button1Down:Connect(function()
if db == true then
return
end
game.ReplicatedStorage.MoveEvent:FireServer(mouse.Hit.p)
end)
You would need to attach a server script having this code
game.ReplicatedStorage.MoveEvent.OnServerEvent:Connect(function(plr, mousepos)
local Dummy = workspace.Dummy
local hum = Dummy.Humanoid
hum:MoveTo(mousepos)
end)
Also add a remote event in replicatedstorage called MoveEvent
I’ll be trying this, thank you.
Alright, so it prints no errors but does nothing. What do I do? (ps: happy cake day!)
What error does it print? Also thanks!
Also, let me give some more explanation.
You click the unit then it moves to where-ever you click next. (thats whats supposed to happen.)
Oh, I read it wrong. Let me try it in a game
It works for me… Is your HumanoidRootPart unanchored?
Ohh… it was, I’ll test it now.
No, it still doesnt work.
did you change the workspace.Dummy
local Dummy = workspace.(The name)
Yes I did.
I don’t know what to do…
Are any other parts anchored? I recommend adding a new dummy with the rig builder and then unanchoring the HumanoidRootPart.
Alright I’ll try that, this will help alot.
Still doesn’t work, where do I put the local script, by the way?
Starter character scripts put it in there, works for me
Try in starter GUI or Starter character scripts
It works! One small problem tho.
I want to make it so when you click the unit it’ll activate this script.
Basically, click the unit you want to move. Then click to a certain position.
How can I do this?
Edit the local script to
local mouse = game.Players.LocalPlayer:GetMouse()
local db = false
local cooldown = 1
local selected = nil
mouse.Button1Down:Connect(function()
if db == true then
return
end
if selected ~= nil then
game.ReplicatedStorage.MoveEvent:FireServer(mouse.Hit.p)
selected = nil
db = true
wait(cooldown)
db = false
else
--make sure its a dummy and not a player
if mouse.Target.Parent.FindFirstChild("Humanoid") and not game.Players:FindFirstChild(mouse.Target.Name) then
selected = mouse.Target.Parent
end
end
end)
Thanks! It works! This is gonna be so much fun to make this game now that I got the basics down!
No problem, also I added a cooldown variable which you can change.