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

Why do my local scripts break after I die? [closed]

Asked by 10 years ago

Hi guys, I've been making some scripts for a friend of mine but when he tests them, he keeps having to revert back to the previous update because some of the local scripts in my GUI keep breaking.

My friend had made a double jump script and I had made a "powerup" button for the GUI. These two things are local scripts and my friend reckons they're conflicting each other.

I have pretty much tried everything to get these to stop breaking but they still persist to break after I die once. They work fine before your first death. After that, they don't work anymore.

The strangest thing is that if I test it by playing solo or using player/server mode, they all work fine and keep working after death.

So, I'm completely stumped so I came here to find some answers. Why do these local scripts keep breaking after I die?

Base "powerup" button local script: (It had been one script earlier and I assumed the scripts broke on death because it was a script and I had tried to make it "too efficient")

wait(1) --Tried a delay to see if that would fix anything.

local player = game.Players.LocalPlayer

local char = player.Character or player.CharacterAdded:wait()
local db = script.Parent.Parent:WaitForChild("Disable")

local select = db.Parent:WaitForChild("Select")

local hum = char:WaitForChild("Humanoid")

function clickFunction()
    if char:FindFirstChild("ForceField") then
        char.ForceField:Destroy()
    else
        Instance.new("ForceField",char)
    end
end

script.Parent.MouseButton1Click:connect(function()
    if db.Value == true then return end
    db.Value = true
    select:Play()
    clickFunction()
    wait(.5)
    db.Value = false
end)

Double jump local script (in StarterPack and was edited by my friend, so it may be a bit inefficient):

repeat wait() until game:GetService("Players")
local Player = game.Players.LocalPlayer

repeat wait() until Player
repeat wait() until Player.Character and Player.Character.Humanoid

local FirstJump = false
local MidJump = false
local Mouse = Player:GetMouse()
TING = false
function onKeyDown(key)
if string.byte(key) == 32 and FirstJump == true and not TING and (MidJump == false or script.Creative.Value == true) then
TING = true
MidJump = true
Player.Character.Torso.Velocity = Player.Character.Torso.Velocity + Vector3.new(0,100,0)
wait(0.1)
TING = false
end
end

function Update()
if Player.Character.Humanoid.Jump == true then
FirstJump = true
else
FirstJump = false
MidJump = false
end
end

Mouse.KeyDown:connect(onKeyDown)
Player.Character.Humanoid.Changed:connect(Update)

Any help is appreciated, thanks!

0
Any errors in the output? Redbullusa 1580 — 10y
0
No errors in output. Probably because of the WaitForChild methods I've been using. Spongocardo 1991 — 10y

Locked by Spongocardo, EzraNehemiah_TF2, and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 10 years ago

Use the Died Event.

game.Players.PlayerAdded:connect(function(plyr) --When there is a player
plyr.CharacterAdded:connect(function(char) --And a players character
char.Humanoid.Died:connect(function() --when the character dies.
plyr.PlayerGui.ScreenGui:Destory() --Destory the gui.
end)
end)
end)
0
Funnily enough, that works. Thank you! Spongocardo 1991 — 10y
0
I thought you would of thought of that since you had 175 reputation. EzraNehemiah_TF2 3552 — 10y
Ad