you should have the bool value in “run” be on by default, otherwise the script won’t start in the first place
It’s so confusing, here is a video of what is happening:
what are you trying to accomplish? Do you want it so that if a tool was taken, it should respawn?
Oh, I see what’s happening. When moving the clone to the workspace, the hierarchy doesn’t match up with what the code is looking for, so it can’t find the ‘run’ value, and therefore can’t make the code run. also, because it’s yielding at a waitforchild(), it never reachs Connection:Disconnect(), so the connection is never disconnected and it keeps cloning when you put it away.
To fix this, change this line of code:
BackUp:WaitForChild("Script"):WaitForChild("run").Value = true
what this is supposed to do is find ‘run’ in the clone, and set it to true, so that the new script starts running.
Howdy! I am here to help. So, this is actually very simple. all you gotta do is make a script into workspace, and put this in:
local function check ()
local check = game.Workspace:FindFirstChild("ToolName")
if not check then
wait(5)
game.Lighting.<ToolName>:Clone().Parent = game.Workspace
end
end
while true do
wait (.1)
check()
end
Hope this helps!
What do I do if I have like 5 different tools that I need to respawn?
You could duplicate the code again and change the tool name. (In the same script, not a whole new one)
What do you mean by “Change this line of code”?
You could put a parameter on check() to specify the tool name, modifying it like so:
local function check(Name)
local check = game.Workspace:FindFirstChild(Name)
if not check then
wait(5)
game.Lighting.<Name>:Clone().Parent = game.Workspace
end
end
Then, say if you have tools labeled “ball” and “sword”, you’ll just need to call
check("ball")
check("sword")
each time you wanted to check if they are missing
Make it match your hierarchy, like
Backup.Script.run.Value = true
or something along those lines, make sure that it does its purpose, which is to set the value of ‘run’ on the new clone to true.
Why doesn’t this do the same thing:
BackUp:WaitForChild("Script"):WaitForChild("run").Value = true
Maybe it’s the name of the script. :WaitForChild() searches the children of the the instance it was called on for any instance with the name given as a parameter. If the name of your script isn’t “Script”, then this line of code will fail, as it will continue searching for something called “Script” that doesn’t exist.
That worked, but there is a script inside of the tool that I want to respawn that makes you eat the tool if you click on it. (The tool is a mushroom.) If I eat the mushroom, it doesn’t respawn, is there a possible fix to this? Like instead of destroying the mushroom after eating it, you set its parent to server storage, then destroy it, so the respawning script can detect when the tool is being deleted, then respawn it.
This should still work with the current script, as when an instance is destroyed, it is no longer a descendant of workspace. If you want the tool to respawn only when it is destroyed, instead of just picked up by the player, change :IsDescendantOf(workspace) to :IsDescendantOf(game). this will check if the tool is in the hierarchy at all.
This however has the problem of deleting the script as well, which will stop the code from working. So a new solution has to be created. One way to fix this is clone the tool right before you delete it. You always have to clone it at that point anyways, so why not do it then.
Sorry for the late response, but the script does not work properly, the same issues are still there, and there are still no errors.
Here are the scripts:
local run = script:WaitForChild("run")
if not run.Value then
run:GetPropertyChangedSignal("Value"):Wait()
end
run.Value = false
local BackUp = script.Parent:Clone()
local Connection
Connection = script.Parent.AncestryChanged:Connect(function()
if not script.Parent:IsDescendantOf(game) then
BackUp.Parent = workspace
BackUp:WaitForChild("ToolRespawn"):WaitForChild("run").Value = true
Connection:Disconnect()
end
end)
Eating script (Not finished):
local module = require(game.ServerScriptService.DamageModule)
script.Parent.Activated:Connect(function(plr)
local tool = script.Parent
local char = tool.Parent
local hmoid = char.Humanoid
local plr = game.Players:GetPlayerFromCharacter(char)
local posionChance
posionChance = math.random(1,8)
if posionChance == 4 then
hmoid.Health /= 2
tool:Clone()
tool:Destroy()
else
hmoid.Health *= 2
tool:Clone()
tool:Destroy()
end
I wouldn’t recommend having the reload script inside the tool, since players who have the tool in there inventory will keep cloning the tool until the same tool in their inventory is in workspace. you might want to try :FindFirstChild() instead
This script is in ServerScriptService
local Backup = game.Workspace.Steve:Clone()
local ToolName = "Steve"
while wait(5) do
if game.Workspace:FindFirstChild(ToolName) == nil then
Backup.Parent = workspace
end
end
What do I do if there are a ton of tools that I need to respawn?
Finally got it working
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Backup = {["Steve"] = ReplicatedStorage.Steve, ["Alex"] = ReplicatedStorage.Alex}
local ToolName = {"Steve", "Alex"}
while wait(5) do
for _,v in pairs(ToolName) do
if game.Workspace:FindFirstChild(v) == nil then
Backup[v]:Clone().Parent = workspace
end
end
end
I don’t really know how to explain it.
I store the tool models into replicated storage, and every 5 seconds it will look through the table of names, so if one is missing it will replace it with the one inside replicated storage.
The main issue with this system is giving multiple tools different spawning times, which is the one of main features in my game, the script works and looks really nice, but I can’t find much use with it in my current game because of that flaw. If there is a way to fix that, please tell me.