So i want to make the player not be able to move whilst the GUI is opened, it works however the player can then move again if they use sprinting. There is no error and any help is wanted!
Here is my GUI script:
local camera = game.Workspace.CurrentCamera
function UpdateCamera()
camera.CFrame = game.Workspace.MenuCamera.CFrame
end
game:GetService("RunService").RenderStepped:Connect(UpdateCamera)
local button = script.Parent.Frame.ImageLabel.PlayButton
local Gui = script.Parent.Frame
local IsOpened = workspace.MenuOpened.Value
IsOpened = true
local sound = Gui.MenuSound
local player = game.Players.LocalPlayer
local OgSpeed = 16
local NewSpeed = 0
local running = game.Workspace.IsSprinting.Value
local function DoStuff()
player.Character:WaitForChild("Humanoid").WalkSpeed = NewSpeed
button.MouseButton1Click:Connect(function()
Gui.Visible = false
player.CameraMode = Enum.CameraMode.LockFirstPerson
player.Character:WaitForChild("Humanoid").WalkSpeed = OgSpeed
IsOpened = false
sound:Stop()
script:Destroy()
end)
end
DoStuff()
Here is the sprint script
local mouse = game.Players.LocalPlayer:GetMouse()
local running = game.Workspace.IsSprinting.Value
local opened = workspace.MenuOpened.Value
running = false
function getTool()
for _, kid in ipairs(script.Parent:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end
mouse.KeyDown:Connect(function (key) -- Run function
key = string.lower(key)
if string.byte(key) == 48 then
running = true
local keyConnection = mouse.KeyUp:Connect(function (key)
if string.byte(key) == 48 then
running = false
end
end)
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
if opened == false then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30
repeat wait () until running == false
keyConnection:disconnect()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
wait()
end
elseif opened == true then return end
end
end)
As you can see Iâve tired implementing it, however when ever i hold sprint whilst the GUI is opened it allows me to move. Both scripts are local scripts btw
You are setting a local value of the running value. If youâd check the IsSprinting value in the Explorer, youâd see the property is set to true (or false, not sure about your system) so you should do it like this:
local running = game.Workspace.IsSprinting
running.Value = false
Hello, thanks for the reply. Sadly, this hasnât fixed my problem. When ever i sprint it still breaks the 0 walk speed and makes the player be able to walk normally without a restriction . Any other ideas?
local mouse = game.Players.LocalPlayer:GetMouse()
local running = game.Workspace.IsSprinting.Value
local opened = workspace.MenuOpened.Value
running = false
function getTool()
for _, kid in ipairs(script.Parent:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end
mouse.KeyDown:Connect(function (key) -- Run function
key = string.lower(key)
if string.byte(key) == 48 then
running = true
local keyConnection = mouse.KeyUp:Connect(function (key)
if string.byte(key) == 48 then
running = false
end
end)
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
if opened == false and game.Players.LocalPlayer.Character.Humanoid.WalkSpeed ~= 0 then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30
repeat wait () until running == false
keyConnection:disconnect()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
wait()
end
elseif opened == true then return end
end
end)