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

(Vector3 expected, got number) ?

Asked by 3 years ago

Hello! I'm a newbie to Roblox scripting so sorry if this article is very obvious to fix. I'm trying to make a part spawn above a player when they press "Q". However, as in the title, it gives me an error. Here is the code and a visual representation of it.

Note: If other parts of the code may be wrong please let me know, I always want to hear problems with my code and potential criticism.

https://gyazo.com/b5fede9003561f9c4530d78de46fbf0f

Here is my visual representation! https://gyazo.com/5e14eed4b3d194d80f56284aede329f2

For people wondering where the script is located,** it is in StartPlayerScripts and is a Local script**

Again, criticism and ways to optimize my code would be very appreciated. Have a good day everyone!

0
if it is a server script change it to a local script MrBarfSquirrel 0 — 3y

2 answers

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

first you didnt get the character's position

second the vector3.new is wrong(assuming your trying to spawn the part on top of your character on line 18) vector only takes number values and doesnt take something like game.Players.LocalPlayer

third line 12 is not needed you will make your code run an extra step that doesnt do anything the code will run without UserInputType

fourth on line 17 part.Size has to be vector3 like this

part.Size = vector3.new(5,5,5)

or you will get an error

on line 16 instead of doing (this wont cause an error but if you give properties before parenting part to workspace you get better performance and idk if this is true but i heard it some where when i just started out coding)(of course you can do it both ways)

("Part", workspace)

do

Instance.new("Part")
part.Properties = awh8d7ga7wudbaw87duyhawj
part.Parent = workspace

now for the part's position

vector3.new(Right Or Left, Up Or Down, Front And Back)

surprisingly even tho you didnt put in number values in the vector correctly the code actually runs when i tested it (line 18)

now heres the solution for everything

local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer or game.Players.LocalPlayer -- you can do it either way but i pefer game:getservice
local abovePlayer = 10

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.Q then
        local part = Instance.new("Part", workspace)
        part.Size = Vector3.new(5,5,5)
        part.CFrame = player.Character.Head.CFrame * CFrame.new(0,abovePlayer,0) -- use cframes to get positions(highly recommended you get into cframes)

    end
end)
--this was very rushed so hoped this helped

this is my first answer post so im sorry if its really bad

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

it is your part.size line. it is set as

Part.size  = 5

this needs to be as the lines of something as:

Part.size = Vector3.new(2, 5, 3)

and should be a server script because then the part will only for the player that pressed the button unless that is what you do want.

Answer this question