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

My script cannot identify the amount of clone, what should I do?

Asked by 5 years ago

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?

1 answer

Log in to vote
0
Answered by
ryan32t 306 Moderation Voter
5 years ago

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)
0
Thanks iamthepurpleguy10 15 — 5y
Ad

Answer this question