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

Clone not working multiple times?

Asked by 3 years ago

When two players use this code, it only clones the part once and the scripts both use that same part for their needs. Does anyone know why this would happen?

Local script in StarterPlayerScripts:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local RepStorage = game:GetService("ReplicatedStorage")
local DeletePart = RepStorage.DeletePart -- remote event
local UIS = game:GetService("UserInputService")
print("1")
UIS.InputBegan:Connect(function(input)
    local Hitposition = Mouse.Hit
    print("2")
    if input.KeyCode == Enum.KeyCode.R then
        print("R Pressed")
        DeletePart:FireServer(Hitposition)
    end
end)

Normal script in ServerScriptService:

local RepStorage = game:GetService("ReplicatedStorage")
local DeletePart = RepStorage.DeletePart
local Cube = RepStorage.Cube:Clone()
local Cooldown = {}
local ExploP = RepStorage.WhiteExplosion -- particles

DeletePart.OnServerEvent:Connect(function(Player, Position)
    if Cooldown[Player.name] then return warn(Player.Name.." is on cooldown")end
    Cooldown[Player.Name] = os.time
    Cube.Name = string.format("%s part", tostring (Player.name))
    Cube.Parent = game.Workspace
    Cube.CFrame = Position
    Cube.Anchored = false
    wait()
    Cube.Anchored = true
    for i = 15,1,-1 do
        Cube.Size = Vector3.new(i+5,i+5,i+5)
        wait(.5)
    end
    ExploP.Parent = Cube
    wait(1)
    ExploP.Parent = RepStorage
    Cube.Parent = RepStorage
    delay(2,function() -- 2 = cooldown time after cube over
        Cooldown[Player.Name] = nil
    end)
end)

1 answer

Log in to vote
1
Answered by
TGazza 1336 Moderation Voter
3 years ago

i see the problem you're only cloning the part once. you need to re-clone the part over and over for each operation something like:

local RepStorage = game:GetService("ReplicatedStorage")
local DeletePart = RepStorage.DeletePart
local CubeRef = RepStorage.Cube:Clone()
local Cooldown = {}
local ExploP = RepStorage.WhiteExplosion -- particles

DeletePart.OnServerEvent:Connect(function(Player, Position)
    if Cooldown[Player.name] then return warn(Player.Name.." is on cooldown")end
    Cooldown[Player.Name] = os.time
    local Cube = CubeRef:Clone()
    Cube.Name = string.format("%s part", tostring (Player.name))
    Cube.Parent = game.Workspace
    Cube.CFrame = Position
    Cube.Anchored = false
    wait()
    Cube.Anchored = true
    for i = 15,1,-1 do
        Cube.Size = Vector3.new(i+5,i+5,i+5)
        wait(.5)
    end
    ExploP.Parent = Cube
    wait(1)
    ExploP.Parent = RepStorage
    Cube.Parent = RepStorage
    delay(2,function() -- 2 = cooldown time after cube over
        Cooldown[Player.Name] = nil
    end)
end)


Hope this helps! :)

Ad

Answer this question