I want to create a plugin that'll help you position parts and do other stuff more easier than the way studio has What I want this script to do is to let you set the value and then change the position of the part to what you set
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local playergui = player.PlayerGui local screen = game.ReplicatedStorage.ScreenGui local x = screen.Xie local y = screen.Yie local z = screen.Zie screen:Clone().Parent = playergui placepart = function(key) local part = Instance.new("Part", workspace) part.Name = "CreatedPart" local setPosition = Instance.new("Vector3Value", part) setPosition.Name = "PartPosition" -- Set Position Values -- setPosition.Value.X = x.Text --Here is the problem error "X cannot be assigned to" setPosition.Value.Y = y.Text --Here is the problem setPosition.Value.Z = z.Text -- Here is the problem part.Position = Vector3.new(setPosition.Value.X,setPosition.Value.Y,setPosition.Value.Z) if key == "x" or key == "X" then game.ReplicatedStorage.ScreenGui:Clone().Parent = playergui end end mouse.KeyDown:Connect(placepart)
Hopefully you can answer my question :)
As you can see here, the coordinate properties of the Vector3 class are marked as read-only. This means that you can't set the X, Y and Z coordinates manually - you can only view/read each of their values. The correct way of creating a Vector3 is by using the Vector3.new() constructor and passing each coordinate value into it.
For example, as you are setting the value of a Vector3Value in your script, you would do the following:
setPosition.Value = Vector3.new(x.Text, y.Text, z.Text) -- Strings will automatically convert to numbers when necessary, so there's no need to use tonumber() here.
Your full script would look something like this (with a few minor tweaks):
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local playergui = player:WaitForChild("PlayerGui") -- Waits for the PlayerGui to become available. local screen = game.ReplicatedStorage:WaitForChild("ScreenGui") -- Wait for the ScreenGui to become available. local x = screen.Xie local y = screen.Yie local z = screen.Zie screen:Clone().Parent = playergui local function placePart(key) -- Small rearrangement of the function's creation so that it's easier to read. local part = Instance.new("Part", workspace) part.Name = "CreatedPart" local setPosition = Instance.new("Vector3Value", part) setPosition.Name = "PartPosition" -- Set Position Value -- setPosition.Value = Vector3.new(x.Text, y.Text, z.Text) part.Position = setPosition.Value -- The value is already a Vector3, you don't need to create a new one to set the part's position. if key == "x" or key == "X" then game.ReplicatedStorage.ScreenGui:Clone().Parent = playergui end end mouse.KeyDown:Connect(placepart) -- It is better to use UserInputService for new work as this is deprecated.
I would also consider using the UserInputService to handle your key bindings as opposed to KeyDown as it is deprecated and should not be used for new work.
I hope my answer helped you. If it did, be sure to accept it.