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

WHy does my E to open door script break after death?

Asked by 3 years ago

I have a game with an E to open door script that works fine but it doesn't work after the player dies, does anyone know how to fix this?

Script:

--< Services local PlayerService = game:GetService('Players') local UserInputService = game:GetService('UserInputService')

--< Variables local Player = PlayerService.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait()

local PlayerGui = Player:WaitForChild('PlayerGui')

local EClick = PlayerGui:WaitForChild('EClick') local Text = EClick.TextLabel

local Activ = false local Obj = nil

--< Events UserInputService.InputBegan:Connect(function(Input) if Activ and Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.E then Obj.Config.DetectEvent:FireServer() end end)

--< Loops while wait() do Obj = nil Activ = false Text.Visible = false for _, Door in pairs(workspace.ElementDoor2:GetChildren()) do local mag = (Character.HumanoidRootPart.Position - Door.Center.Position).magnitude if mag <= Door.Config.Range.Value then Text.Visible = true Activ = true Obj = Door end end end

1 answer

Log in to vote
0
Answered by 3 years ago

If it's a local script, put it in StarterCharacter scripts so that it resets after death.

Ad

Answer this question