Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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
0
Please provide some more information (the errors, the lines in which they are in etc) WoTrox 345 — 3y
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 TheUltimateTNTFriend 109 — 3y
0
to put it simply its a require script. But when i require it once it wont work again its broken TheUltimateTNTFriend 109 — 3y
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. JesseSong 3916 — 3y
View all comments (7 more)
0
what does that mean? TheUltimateTNTFriend 109 — 3y
0
and what u mean by loop? TheUltimateTNTFriend 109 — 3y
0
A loop is something that repeats continuously. JesseSong 3916 — 3y
0
e.g. for loop, while true do loop, repeat loops JesseSong 3916 — 3y
0
can u post a example of a loop and why i need it? TheUltimateTNTFriend 109 — 3y
0
itll help because im not really sure what do i do with a loop and why i need it TheUltimateTNTFriend 109 — 3y
0
post your solved answer in answer. JesseSong 3916 — 3y

1 answer

Log in to vote
1
Answered by
WoTrox 345 Moderation Voter
3 years ago

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
0
i already solved it but ill still accept your answer TheUltimateTNTFriend 109 — 3y
Ad

Answer this question