Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm having trouble with making a spawn part tool, can someone help?

I'm sorry if this is an easy question, but I'm having a lot of trouble with this as I'm new to scripting. So basically I'm trying to make a tool that would spawn a part at player's mouse position. I've kept trying different ways but none of them succeeded!

Local-script of the tool:

local event = game.ReplicatedStorage.Mousepos
local tool = script.Parent
local player = game.Players.LocalPlayer


tool.Activated:Connect(function()
	local m = player:GetMouse()
	local mp = m.Hit.Position
		event:FireServer(mp)
	end)

Server-Side Script:


local e = game.ReplicatedStorage.Mousepos

e.OnServerEvent:Connect(function(mp)
	local part = Instance.new("Part")
	part.Parent = game.Workspace.Spawnedparts
	part.Position = mp
end)

Console Error:

ServerScriptService.part:6 invalid argument #3 (Vector3 expected, got Instance)

Testing Style:

Play

Server Side Script Location: game.ServerScriptService.part

*Outcome: The Part Spawns at the bottom of the map

  • Expectations: Part Spawns at the player's mouse position

I've tried changing the part.Position part to part.Position = Vector3.new(mp.X, mp.Y, mp.Z) changing the local script to local mp = m.Hit.p + Vector3.new(0,0,0) and a few different solutions that I won't list since they're pretty similar to these.

I'm not sure why it doesn't work, I tried searching on the internet for stuff like "how to get players mouse position" thinking I'm doing something wrong but I couldn't find much, so I came here to ask for help.

####Re-edited by JesseSong!

2 comments

0

fixed codeblock +grammar

0

Sorry and thanks.

1 answer

e.OnServerEvent:Connect(function(player,mp)
	    local part = Instance.new("Part")
	    part.Parent = game.Workspace.Spawnedparts
	    part.Position = mp
	end)

try it should work

2 comments

0

Same error

0

Still doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.