I’m making a thing where you can press a keybind on someone and it will force them to follow your mouse for a few seconds, but I’ve run into 2 issues.
I’m getting 2 errors from the module script which handles it:
Attempt to index nil with 'MoveTo'
and
Attempt to index nil with 'Position'
Here’s my scripts:
server script which sends to the module
--// Services
local Players = game:GetService('Players')
local TweenService = game:GetService('TweenService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
--// Items
--# Objects
local Events = ReplicatedStorage:FindFirstChild('HISSES')
local SpellEvent = Events:FindFirstChild('SpellEvent')
local Powers = require(script.Powers)
--# Variables
SpellEvent.OnServerEvent:Connect(function(Player, Power, Target, State, Mouse)
if Power == 'Healing' then
Powers.Healing(Player.Character, Target)
elseif Power == 'Concillium' then
Powers.Concillium(Player, Target, State, Mouse)
print(Target.Name) -- this doesn't print, i dont know why
print(Target) -- this also doesn't print
end
end)
here’s the module script
--// Services
local TweenService = game:GetService('TweenService')
--// Items
--# Objects
local Effects = script:FindFirstChild('Effects')
local Animations = require(script:FindFirstChild('Animations'))
--# Variables
local Powers = {}
function Powers.Concillium(Caster, Target, State, mousePos)
if State == 'stop' then
Target:FindFirstChildWhichIsA('Humanoid'):MoveTo(Target.PrimaryPart.Position) -- 'Position' error coming from here
else
Target:FindFirstChildWhichIsA('Humanoid'):MoveTo(mousePos) -- 'MoveTo' error coming from here
end
end
and here’s the local script
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local Event = game.ReplicatedStorage:WaitForChild("HISSES"):WaitForChild("SpellEvent")
local debounce = false
local cooldown = false
local mouse = player:GetMouse()
local readyToCast = false
local held = false
UIS.InputBegan:Connect(function(key, isTyping)
if isTyping then return end
if key.KeyCode == Enum.KeyCode.Z and debounce == false and cooldown == false and held == false then
readyToCast = true
cooldown = true
debounce = true
held = true
local timeHeld = 0
Event:FireServer("Concillium", mouse.Target, 'start', mouse.Hit.Position)
while held == true do
wait(1)
timeHeld += 1
if timeHeld > 45 then
Event:FireServer("Concillium", mouse.Target.Parent, 'stop', mouse.Hit.Position)
held = false
wait(30)
cooldown = false
debounce = false
end
end
end
end)
UIS.InputEnded:Connect(function(key, isTyping)
if isTyping then return end
if key.KeyCode == Enum.KeyCode.Z and readyToCast == true then
readyToCast = false
Event:FireServer("Concillium", mouse.Target.Parent, 'stop', mouse.Hit.Position)
wait(30)
cooldown = false
debounce = false
end
end)