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 4 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:

01local Players = game:GetService("Players")
02local LocalPlayer = Players.LocalPlayer
03local Mouse = LocalPlayer:GetMouse()
04local RepStorage = game:GetService("ReplicatedStorage")
05local DeletePart = RepStorage.DeletePart -- remote event
06local UIS = game:GetService("UserInputService")
07print("1")
08UIS.InputBegan:Connect(function(input)
09    local Hitposition = Mouse.Hit
10    print("2")
11    if input.KeyCode == Enum.KeyCode.R then
12        print("R Pressed")
13        DeletePart:FireServer(Hitposition)
14    end
15end)

Normal script in ServerScriptService:

01local RepStorage = game:GetService("ReplicatedStorage")
02local DeletePart = RepStorage.DeletePart
03local Cube = RepStorage.Cube:Clone()
04local Cooldown = {}
05local ExploP = RepStorage.WhiteExplosion -- particles
06 
07DeletePart.OnServerEvent:Connect(function(Player, Position)
08    if Cooldown[Player.name] then return warn(Player.Name.." is on cooldown")end
09    Cooldown[Player.Name] = os.time
10    Cube.Name = string.format("%s part", tostring (Player.name))
11    Cube.Parent = game.Workspace
12    Cube.CFrame = Position
13    Cube.Anchored = false
14    wait()
15    Cube.Anchored = true
View all 27 lines...

1 answer

Log in to vote
1
Answered by
TGazza 1336 Moderation Voter
4 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:

01local RepStorage = game:GetService("ReplicatedStorage")
02local DeletePart = RepStorage.DeletePart
03local CubeRef = RepStorage.Cube:Clone()
04local Cooldown = {}
05local ExploP = RepStorage.WhiteExplosion -- particles
06 
07DeletePart.OnServerEvent:Connect(function(Player, Position)
08    if Cooldown[Player.name] then return warn(Player.Name.." is on cooldown")end
09    Cooldown[Player.Name] = os.time
10    local Cube = CubeRef:Clone()
11    Cube.Name = string.format("%s part", tostring (Player.name))
12    Cube.Parent = game.Workspace
13    Cube.CFrame = Position
14    Cube.Anchored = false
15    wait()
View all 28 lines...

Hope this helps! :)

Ad

Answer this question