So im making this mind control script where if player1 presses "c" on player2, player2's controls will be disabled and player1's camera switches to player2's camera, at that point when player1 presses WASD then player2's character will move as so...
The localscript is inside StarterPack and a remotefunction "RemotePossess" is a child of that localscript, the receiver script being a server script is a child of the remotefunction
Localscript
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Key = nil local MoveKey = nil local isTyping = false local Enabled = true local ButtonDown = true local camera = game.Workspace.CurrentCamera --make sure player isnt typing game:GetService("UserInputService").InputBegan:connect(function(InputObj) if InputObj.KeyCode == Enum.KeyCode.Slash then local finishEvent = nil isTyping = true finishEvent = game:GetService("UserInputService").InputBegan:connect(function(InputObj) if InputObj.KeyCode == Enum.KeyCode.Return or InputObj.UserInputType == Enum.UserInputType.MouseButton1 then isTyping = false finishEvent:disconnect() end end) end end) -------------------------------------------------------- game:GetService("UserInputService").InputBegan:connect(function(Input, gameProcessedEvent) if isTyping == true or Enabled == false then return end --checks if player is typing if Input.KeyCode == Enum.KeyCode.C then Key = "C" Enabled = false ButtonDown = true if mouse.Target.Parent:FindFirstChild("Humanoid") == nil then if mouse.Target and mouse.Target.Parent then print("not found") print(mouse.Target.Parent) end end if mouse.Target.Parent:FindFirstChild("Humanoid") ~= nil then --and doesnt contain "animal" stringvalue print("Humanoid found") local mousehit = mouse.Hit local mouseTarget = mouse.Target local possessedCheck = mouseTarget.Parent.Possessed.Value script.RemotePossess:FireServer(player, Input.KeyCode) camera.CameraSubject = mouseTarget.Parent.Humanoid possessedCheck = true --game:GetService("UserInputService").InputBegan:connect(function(InputObject, gameProcessedEvent) --if InputObject.keyCode == Enum.KeyCode.W then MoveKey = "W" --end --end) end end end)
Serverscript
local ButtonDown = false local enabled = true local plr = script:FindFirstAncestorWhichIsA("Player") print(plr.Name) local Mouse = plr:GetMouse() script.Parent.OnServerEvent:Connect(function(player, Input, action, mouseTarget, mousehit) local c = player.Character.Humanoid print(Input) if action == "Release" then ButtonDown = false end if action == "Possess" and enabled == true then spawn(function() enabled = false ButtonDown = true wait() while ButtonDown == true and mouseTarget.Parent:FindFirstChild("Humanoid") ~= nil do if Input.KeyCode == Enum.KeyCode.W then mouseTarget.Parent.Humanoid:MoveTo(mousehit.Position) end --mouseTarget.Parent.Humanoid:MoveTo() wait() end enabled = true ButtonDown = false end) end if action == "Move" and enabled == false then end end)
it currently comes up with no errors but the npc that is posessed refuses to move when W is prompted within the OnServerEvent/receiver script, im pretty sure wasd/ player movement has something to do with the camera so I tried to use the position of where mousehit is and possibly get a cframe from that but it didnt work
I know it has something to do with where the camera is pointed and im gonna have to reference A, S and D unless theres a shortcut to doing that.
I know theres a command for like player.Humanoid.Jump = true and im not sure if theres something like that for walking.