Unable to assign property Position. Vector3 expected, got Vector2

Hello! So I am trying to it make to where when you equip a certain tool, you will be able to place a block that explodes whenever the mouse clicks. It works, but I get the error in the title.
Here is my code (local script:)

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ExplosionBlock = ReplicatedStorage:WaitForChild("ExplosionBlock")

local tool = script.Parent

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local MousePos = UserInputService:GetMouseLocation()

Mouse.Button1Down:Connect(function()
	ExplosionBlock.Parent = game.Workspace
	ExplosionBlock.Position = MousePos
end)

Code in a regular script parented to the block in RS:

local Sound = script.Parent:WaitForChild("Sound")

while true do
	task.wait(1)
	script.Parent.BrickColor = BrickColor.random()
end

local function explode()
	while true do
		task.wait(1)
		Sound:Play()
	end
	
	local Explosion = Instance.new("Explosion")
	Explosion.Parent = game.Workspace
	Explosion.Position = script.Parent.Position
end

explode()

I think I could maybe optimize it by using RemoteEvents or something.

If you think you know what went wrong, please let me know. Thank you and have a wonderful day! :slight_smile:

1 Like

:GetMouseLocation() gives you the actual x, y coordinates, not a 3d position. You can just use Mouse.Hit instead.

Code:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local ExplosionBlock = ReplicatedStorage:WaitForChild("ExplosionBlock")
local tool = script.Parent

--//Functions
Mouse.Button1Down:Connect(function()
	local newExplosionBlock = ExplosionBlock:Clone()
	newExplosionBlock.Position = Mouse.Hit.Position
	newExplosionBlock.Parent = workspace
end)

This might not work btw, I just assumed your current code is in a working state.

1 Like

It worked! Thank you so much!

But I just noticed that none of the code in the block script works. Can you tell why?

It’s because you’re cloning the part on the client side, but that block script is server side. You’re gonna have to use a RemoteEvent, or do all the effects on the client.

If I did everything on the client, would it look like this?

--Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--Variables
local tool = script.Parent
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local ExplosionBlock = ReplicatedStorage:WaitForChild("ExplosionBlock")
local Sound = ExplosionBlock:WaitForChild("Sound")

--Functions
Mouse.Button1Down:Connect(function()
	local newBlock = ExplosionBlock:Clone()
	newBlock.Position = Mouse.Hit.Position
	newBlock.Parent = workspace
end)

while task.wait(1) do
	ExplosionBlock.BrickColor = BrickColor.random()
	Sound:Play()
end

local function explode()
	local Explosion = Instance.new("Explosion")
	Explosion.Parent = game.Workspace
	Explosion.Position = ExplosionBlock.Position
end

explode()

No, you want to put that inside the .Button1Down.

Code:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local tool = script.Parent
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local ExplosionBlock = ReplicatedStorage:WaitForChild("ExplosionBlock")

--//Functions
Mouse.Button1Down:Connect(function()
	local newBlock = ExplosionBlock:Clone()
	newBlock.Position = Mouse.Hit.Position
	newBlock.BrickColor = BrickColor.random()
	newBlock.Parent = workspace
	
	task.spawn(function()
		while task.wait(1) and newBlock:IsDescendantOf(workspace) do
			newBlock.BrickColor = BrickColor.random()
		end
	end)
	
	local Explosion = Instance.new("Explosion")
	Explosion.Position = newBlock.Position
	Explosion.Parent = workspace
	
	newBlock.Sound:Play()
end)
1 Like

It works, but I want the part to play the sound and change color for 5 seconds then explode.

Then use a for loop instead.

Code:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local tool = script.Parent
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local ExplosionBlock = ReplicatedStorage:WaitForChild("ExplosionBlock")

--//Functions
Mouse.Button1Down:Connect(function()
	local newBlock = ExplosionBlock:Clone()
	newBlock.Position = Mouse.Hit.Position
	newBlock.BrickColor = BrickColor.random()
	newBlock.Parent = workspace
	
	for i = 1, 5 do
		newBlock.Sound:Play()
		newBlock.BrickColor = BrickColor.random()
		task.wait(1)
	end

	local Explosion = Instance.new("Explosion")
	Explosion.Position = newBlock.Position
	Explosion.Parent = workspace
	
	newBlock:Destroy()
end)
1 Like

It works! Thank you so much!

I’m having problems with another script, can I DM you the code?

I would prefer you make a new post, because I have things to do right now.

Enemy NPC not respawning - Help and Feedback / Scripting Support - Developer Forum | Roblox
Here is the post I made a few days ago.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.