I am trying to make a script that will stop the player from moving and will make a GUI appear when they die. When I die for the first time the script works perfectly; however, when I die the second time it doesn't. Any help?
Script in question:
-- Variables
local looky = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local storage = game:GetService("ReplicatedStorage")
-- Handles when the play button is clicked
script.Parent.Playbutton.MouseButton1Click:Connect(function()
local backpack = game.Players.LocalPlayer.Backpack
for i, child in pairs(backpack:GetChildren()) do
if child:IsA("Tool") then
storage.RemoteEvents.MobileOn:FireServer()
script.Parent.Visible = false
repeat
wait()
looky.CameraType = Enum.CameraType.Custom
until looky.CameraType == Enum.CameraType.Custom
else
script.Parent.Parent.NoSword.Position = UDim2.new(0.321, 0,0.321, 0)
end
end
end)
-- The part that is giving me trouble
hum.Died:Connect(function()
wait(5)
storage.RemoteEvents.MobileOff:FireServer()
repeat wait()
looky.CameraType = Enum.CameraType.Scriptable
until looky.CameraType == Enum.CameraType.Scriptable
repeat wait()
looky.CFrame = game.Workspace.startingcamerapos.CFrame
until looky.CFrame == game.Workspace.startingcamerapos.CFrame
script.Parent.Visible = true
end)
Script that updates the WalkSpeed and JumpPower when the BoolValue changes:
local mobile = Instance.new("BoolValue", game:GetService("ReplicatedStorage"))
mobile.Name = "mobile"
mobile.Value = false
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.Humanoid.WalkSpeed = 0
char.Humanoid.JumpPower = 0
mobile.Changed:Connect(function()
if mobile.Value == true then
char.Humanoid.WalkSpeed = 24
char.Humanoid.JumpPower = 50
elseif mobile.Value == false then
char.Humanoid.WalkSpeed = 0
char.Humanoid.WalkSpeed = 0
end
end)
end)
end)

1 comment
You're looking at the same Humanoid everytime, once that Humanoid dies it's gone and a new one will replace it. Try making a CharacterAdded event and doing Character.WaitForChild('Humanoid')