I made a tool that when you equip it, a shadow copy of it will appear, according to the mouse position.
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local object = game.ReplicatedStorage.Tool.FirePit event = game.ReplicatedStorage.RemoteEvent script.Parent.Equipped:Connect(function() local invisible = object:Clone() invisible.Parent = workspace.CurrentCamera invisible.CFrame = mouse.Hit invisible.UsePartColor = true invisible.CanCollide = false while true do wait(.01) invisible.CFrame = mouse.Hit mouse.Button1Down:Connect(function() invisible:Destroy() event:FireServer(mouse.Hit,object) end) end end)
event:
local event = game.ReplicatedStorage.RemoteEvent event.OnServerEvent:Connect(function(player,hit,object) local clone = object:Clone() clone.Parent = workspace clone.CFrame = hit clone.Fire.Enabled = true clone.Transparency = 0 end)
It spawn up to thousands firepit, what should I do?
Problem is that you're doing:
while true do mouse.Button1Down:Connect(function() end) end
Doing that will constantly create a ton of Button1Down Events. Then when you Left Click. It runs all the Button1Down Events that it created. You should use a Mouse.Move Event outside of Tool.Equipped Event instead of using a while loop. Also, don't use Mouse.Button1Down when the script is inside of a tool. Just use Tool.Activated.
The script layout should, in some way, look like this:
script.Parent.Equipped:Connect(function() -- tool equipped end) mouse.Move:Connect(function() -- tool isEquipped Checks -- FirePit CFrame Updates end) script.Parent.Activated:Connect(function() -- "tool Activated" aka "Left Clicked with Tool Equipped" end)