Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you summon a part on a mouse's target?

Asked by 5 years ago

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)

0
Try putting Thunder.Position = target MadWorlds 84 — 5y
0
I tried that but it did not work turbomegapower12345 48 — 5y
0
Sorry, I meant Thunder.Position = target.Position MadWorlds 84 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You attempted to set an object to a 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
)
0
I oh ok thx turbomegapower12345 48 — 5y
Ad

Answer this question