Hi, I am trying to make a script that summons a part on a players target. The issue I am having is that when I tell the part to go to the target (mouse target) an error appears on the output. It says
19:56:36.799 - ContextActionService: Unexpected error while invoking callback: Players.turbomegapower12345.PlayerScripts.ZeusPowers:22: bad argument #3 to 'CFrame' (CFrame expected, got Vector3)
But when I do CFrame, another error appears
20:00:30.572 - ContextActionService: Unexpected error while invoking callback: Players.turbomegapower12345.PlayerScripts.ZeusPowers:22: bad argument #1 to 'new' (Vector3 expected, got nil)
How do I fix these errors and make a part summon on the mouse target?
Here is my script!
local player = game.Players.LocalPlayer local character = player.CharacterAdded:wait() local humanoid = character.Humanoid local torso = character.UpperTorso local mouse = player:GetMouse() local target = mouse.Target local God = player.PlayerGui.ChooseCharacter.God --BREAKLINE-- function onKeyPress(actionName, userInputState, inputObject) if userInputState == Enum.UserInputState.Begin then if inputObject.KeyCode.Name ==("E") then if God.Value ==("Zeus") then print("THUNDERBOLT!") local Thunder = Instance.new("Part",workspace) Thunder.CFrame = CFrame.new(target) end end end end game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R, Enum.KeyCode.E)
CFrame
.local player = game.Players.LocalPlayer local character = player.CharacterAdded:Wait() -- :wait is deprecated, use :Wait local humanoid = character.Humanoid local torso = character.UpperTorso local mouse = player:GetMouse() local target local God = player.PlayerGui.ChooseCharacter.God --BREAKLINE-- local function onKeyPress(actionName, userInputState, inputObject) target = mouse.Target if userInputState == Enum.UserInputState.Begin then if God.Value == "Zeus" then -- brackets redundant print("THUNDERBOLT!") local Thunder = Instance.new("Part") -- parent argument deprecated Thunder.CFrame = CFrame.new(target.Position) -- set CFrame to position Thunder.Parent = workspace end end end game:GetService("ContextActionService"):BindAction( "keyPress", onKeyPress, false, Enum.KeyCode.R, Enum.KeyCode.E )