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

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

Asked by 3 years ago
Edited by JesseSong 3 years ago

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!

0
fixed codeblock +grammar JesseSong 3916 — 3y
0
Sorry and thanks. black13442 0 — 3y

1 answer

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

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an 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

0
Same error black13442 0 — 3y
0
Still doesnt work black13442 0 — 3y
Ad

Answer this question