Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script break when i try to reuse it after i reset my character when its used?

To explain i made a script that i can run for myself and all the features work perfectly. the only problem is that when i die or get resetted while i am running the script i cant re run it again in my next life. i dont know what exactly is the problem all i get are errors saying that the script does not contain the elements which are supposed to be in the script. please help. This is my main require script, u dont need to know the others as they already work.

local Bruh = {}
function Bruh.Give(Name)
	local plr = game.Players:FindFirstChild(Name)
	wait(0.5)
	script.RemoteEvent.Parent = plr.Character
	script.AttackScript.Parent = plr.Character
	script.LocalScript.Parent = plr.Character
	plr.Character.Humanoid.MaxHealth = 100000000000000000000000000000000000000000000
	plr.Character.Humanoid.Health = 100000000000000000000000000000000000000000000
	plr.Character.Humanoid.WalkSpeed = 50
script.ScreenGui.Parent = plr:WaitForChild("PlayerGui")
script.BanGui.Parent = plr:WaitForChild("PlayerGui")
	script.Type.Parent = plr:WaitForChild("PlayerGui")
	script.Chara.Parent = plr:WaitForChild("PlayerGui")
	script.Classic.Parent = plr:WaitForChild("PlayerGui")
	script.Dust.Parent = plr:WaitForChild("PlayerGui")
	script.Error.Parent = plr:WaitForChild("PlayerGui")
	script.Tut.Parent = plr:WaitForChild("PlayerGui")
	script.Race.Parent = plr.Character
	script.BillboardGui.Parent = plr.Character.Head
	plr.Character.Race:Play()
	script:Destroy()
end
return Bruh

11 comments

0

Please provide some more information (the errors, the lines in which they are in etc)

0

its not a error basically u see i have this entire script which contains alot of elements that gives me a good performance. But it cant be re runned for some reason i dont know why

0

to put it simply its a require script. But when i require it once it wont work again its broken

0

When a character dies/reset all the containers get replaced with a new one, that is why your code isn't working. Simply add a loop to fix the issue.

0

what does that mean?

0

and what u mean by loop?

0

A loop is something that repeats continuously.

0

e.g. for loop, while true do loop, repeat loops

0

can u post a example of a loop and why i need it?

0

itll help because im not really sure what do i do with a loop and why i need it

0

post your solved answer in answer.

1 answer

✓ Accepted answer

When you first run the script, everything you want to give the player (e.g. the RemoteEvent, AttackScript, LocalScript) will be moved. So when the player dies and loses, you cant give them to him again, since they were moved and are not there at the moment.

You could Clone them instead of just moving.

local Bruh = {}
function Bruh.Give(Name)
    local plr = game.Players:FindFirstChild(Name)
    wait(0.5)
    script.RemoteEvent:Clone().Parent = plr.Character
    script.AttackScript:Clone().Parent = plr.Character
    script.LocalScript:Clone().Parent = plr.Character
    plr.Character.Humanoid.MaxHealth = math.huge --math.huge is basically infinity, so its better to use that
    plr.Character.Humanoid.Health = math.huge
    plr.Character.Humanoid.WalkSpeed = 50
script.ScreenGui:Clone().Parent = plr:WaitForChild("PlayerGui")
script.BanGui:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Type:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Chara:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Classic:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Dust:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Error:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Tut:Clone().Parent = plr:WaitForChild("PlayerGui")
    script.Race:Clone().Parent = plr.Character
    script.BillboardGui:Clone().Parent = plr.Character.Head
    plr.Character.Race:Play()
end
return Bruh

1 comment

0

i already solved it but ill still accept your answer

This discussion is preserved as it was. New answers, comments, and votes are closed.