So I am not the best at scripting but not too bad either and I am a bit confused why when I clone the script then destroy it it copies the wrong script more context: I am making a simulator where you can buy clones but I just cant get my head around how tags work so basically this script is in a dummy something the clone will kill but I don't know how to use tags so I make it clone itself then destroy itself can someone please tell me if this will work and if it wont what's the problem?
> `local Humanoid = script.Parent.Humanoid function Dead() local clone = script.Parent.Parent.Parent.Folder:GetChildren() for _, v in pairs(clone) do local name = v.Name local plr = game.Players:FindFirstChild(name) plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + game.ServerStorage["CloneVal's"].CashVal.Value plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1 local scriptclone = script:Clone() scriptclone.Parent = script.Parent scriptclone.Name = "MoneyScriptClone" scriptclone.Disabled = false script:Destroy() end end Humanoid.Died:Connect(Dead) `
so basically there is a script (the script above) in a folder in workspace that gets copied into this dummy that a clone of the player would kill and each time it gives the player money so I have to find the clones name then find it as a player then give the player leaderstats but I have recently figured out that it will only work once because the humanoid or character resets and the best way is to use tags but I cant get my head around them so I make the script destroy itself after cloning itself but instead what it does is clones the script to make it respawn but what makes me think it is a glitch is that it keeps cloning the wrong script when the dummy dies even though the script that clones itself is gone and it cant be cloned by the script that gets cloned in the first place because it is deactivated and only the clone gets activated.
all help is appreciated
The word 'script' is a so called keyword in Roblox lua, this means that it's always available regardless of context. The script
keyword is used to reference the script which runs the code, so for example using script.Parent.BrickColor = BrickColor.new("Really red")
would change the color of the parent of the script.
All of this means that keywords shouldn't be used as variable names, as in your case it would prioritize the keyword over the variable name, thus cloning the script which runs the code and not the script you want to target.
You could rename the 'script' variable to something like 'script_' or 'script0' or anything which isn't just 'script'
Sorry if I wasted some of your time but the answer was actually that it was a different script that was breaking it so all I have done is merged them together