Hello! I’m currently having an issue for cloning a instance. What I want to achieve is that every time a player joins a part is created. Another joins, another part/instance is created. I’ve tried using things like PlayerAdded, although it just doesn’t work
Here is my code:
local cloned = game.ServerStorage.bright:Clone()
local repstor = game.ReplicatedStorage
local on = repstor.FlashOn
local off = repstor.FlashOff
local weld = Instance.new("WeldConstraint")
local charVariable
local bright = Instance.new("Part") -- The Instance
bright.Name = "bright"
bright.Transparency = 1
bright.Size = Vector3.new(0.125, 0.125, 0.125)
bright.CanCollide = true
bright.Anchored = false
local lighting = Instance.new("SpotLight")
lighting.Angle = 90
lighting.Brightness = 0
lighting.Shadows = true
lighting.Parent = bright
local brightclone = bright:Clone()
brightclone.Name = "brightclone"
game.Players.PlayerAdded:Connect(function() -- Every time a player joins
brightclone.Parent = game.Workspace
end)
if brightclone then -- detects if there is a clone, then applies lighting
game.Players.PlayerAdded:Connect(function(player)
local backpack = player:FindFirstChildOfClass("Backpack")
player.CharacterAdded:Wait()
charVariable = player.Character
weld.Parent = brightclone
weld.Part0 = brightclone
repstor.ForSecondLight.OnServerEvent:Connect(function()
weld.Part1 = charVariable.flashlight.Handle
brightclone.Position = charVariable.flashlight.lightpart.Position
brightclone.Orientation = charVariable.flashlight.lightpart.Orientation
brightclone.CanCollide = false
wait()
end)
end)
on.OnServerEvent:Connect(function() -- Other Lighting
brightclone.SpotLight.Brightness = 5
end)
off.OnServerEvent:Connect(function()
brightclone.SpotLight.Brightness = 0
end)
end
(Every time I run this script on a multiplayer server it only clones once, not twice, etc.)