Hi im trying to make a script where a specific player can click a gui button (me) and itll freeze everyone (specifically making me sing and making them sleep) ive tried 2 methods and didnt work this took me 3 days trying to figure this out heres the script
local YuiiGui = game.Players.YuiiIsOld.PlayerGui local Yuii = game.Workspace.YuiiIsOld local Everyone = script.Parent local SleepEvent = game.Workspace.SleepEvent local FreezeEvent = game.Workspace.FreezeEvent local StartFreeze = script.Parent.FreezeHandler local YuiiHum = game.Workspace.YuiiIsOld.Humanoid YuiiGui.YuiiIsOld.Frame.Sing.MouseButton1Click:Connect(function() YuiiGui.YuiiIsOld.Frame.Visible = false print("Singing!") script.Lullaby:Play() Yuii.Sing.Disabled = false Yuii.Animate.Disabled = true FreezeEvent:Play() StartFreeze.Disabled = false wait(8) YuiiGui.YuiiIsOld.Frame.Sing.Visible = false YuiiGui.YuiiIsOld.Frame.Visible = true script.Lullaby:Stop() Yuii.Sleep.Disabled = true Yuii.Animate.Disabled = false Yuii.Sing.Disabled = true YuiiHum.WalkSpeed = 16 YuiiHum.JumpPower = 50 Everyone.Sleep.Disabled = false Everyone.Animate.Disabled = true wait(5) Everyone.Sleep.Disabled = true Everyone.Animate.Disabled = false Everyone.FreezeHandler.Disabled = true Everyone.FreezeHandler:Clone() Everyone.FreezeHandler:Destroy() wait(1) YuiiGui.YuiiIsOld.Frame.Sing.Visible = true end)
this is inside a local script located at StarterCharacterScripts the other script named FreezeHandler has this
if game.Workspace.FreezeEvent.Playing == true then print("Successfully Frozen") script.Parent.Humanoid.WalkSpeed = 0 script.Parent.Humanoid.JumpPower = 0 elseif game.Workspace.FreezeEvent.Playing == false then script.Parent.Humanoid.WalkSpeed = 16 script.Parent.Humanoid.JumpPower = 50 end
the animation works dont worry, the walkspeed however wont change nor the jumppower
Assuming, that the code you have mentioned in LocalScript
is that only, it might execute once when the player's Character
is loaded.
In order to fix that, you can add a while
loop to check the values constantly.
while wait() do -- Loops the code 33 times a second (in order to check constantly) if game.Workspace.FreezeEvent.Playing == true then print("Successfully Frozen") script.Parent.Humanoid.WalkSpeed = 0 script.Parent.Humanoid.JumpPower = 0 elseif game.Workspace.FreezeEvent.Playing == false then script.Parent.Humanoid.WalkSpeed = 16 script.Parent.Humanoid.JumpPower = 50 end end
Lemme know if it helps!