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

how to make a part spawn at your mouse cursor when you click? [closed]

Asked by 3 years ago

How do I make a part spawn at my mouse cursor when I click? And how do I make it despawn?

Closed as Not Constructive by IAmNotTheReal_MePipe and JesseSong

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

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

When asking a question please provide previous attempts that you have tried so you don't ask a "Make me this" type of question, anyways, since this is a simple question I'll answer it.

What you'll need are 3 things: A RemoteEvent, a LocalScript, and a ServerScript

First of all, let's make a RemoteEvent in ReplicatedStorage and name it GeneratePart

Secondly, let's have our LocalScript, which I had placed in StarterPlayerScripts

This script will fire the RemoteEvent so that way other players will be able to see the parts being generated, you should have this inside of it:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("GeneratePart")

mouse.Button1Down:connect(function()
    Event:FireServer(mouse.Hit.p)
end)

Finally, put the ServerScript in ServerScriptService, which will respond to the Event being fired, and put in the following:

local RP = game:GetService("ReplicatedStorage")

local Event = RP:WaitForChild("GeneratePart")

local DespawnTime = 1

Event.OnServerEvent:connect(function(player, Pos)
    local Part = Instance.new("Part",workspace)
    Part.Position = Pos
    wait(DespawnTime)
    Part:Destroy()
end)
0
If you could help me for future reference what does (mouse.H.p) mean in line 8 after you fire your event? Does it get the Mouses Hit Position? M9F 94 — 3y
Ad