i have a basic cloning script, but when I dup the script to another block, it don’t work
here’s the script:
script.Parent.Touched:Connect(function(hit)
local fire = game.ReplicatedStorage.Fire:Clone()
fire.Parent = hit.Parent
wait(0.5)
fire:Destroy()
print("lol")
end)
Can you tell more about the issue? Are there any errors? Does nothing happen? Have you tried checking manually if it did anything? What about the “print(“lol”)”, did it log?
it did print, but the script wasn’t working OR I somehow deleted the original?
You probably want to mention ReplicatedStorage (and even the Object you want to clone) out of the Touched event.
Try using this code for your script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Fire = ReplicatedStorage:WaitForChild("Fire")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
print("Humanoid exists")
local CloneFire = Fire:Clone()
print("Cloned the 'Fire' Object")
CloneFire.Parent = hit.Parent
print("Parented the 'Fire' Object")
wait(0.5)
CloneFire:Destroy()
print("Cloned 'Fire' Object has been destroy!")
print("lol")
end
end)
how would i make it only clone once? i just realized its cloning too much lol
You can use debounces to stop it from cloning too much. But there is another method where you can check if the object already exists in the character or not.
Here is the full code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Fire = ReplicatedStorage:WaitForChild("Fire")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if not hit.Parent:FindFirstChild(Fire.Name) then -- only if the object is not inside the character
print("Humanoid exists")
local CloneFire = Fire:Clone()
print("Cloned the 'Fire' Object")
CloneFire.Parent = hit.Parent
print("Parented the 'Fire' Object")
wait(0.5)
CloneFire:Destroy()
print("Cloned 'Fire' Object has been destroy!")
print("lol")
end
end
end)