Avoiding player movement if UI's still showing!

Hello, I’m DragonDarkVader! Also known as one of the Developers of Sage. Some of the Developers are having trouble fixing this problem which is to avoid Player Movement when the loading screen is still Visible…

INSIDE THE MODEL

Items

RESULT OF THE MODEL

So the problem is, we want to disable the player movement when the UI is still showing…But everytime i try to do something about it, It doesn’t work.

VIDEO FUNCTIONS

robloxapp-20221223-1722474.wmv (1.1 MB)

THE CODE INSIDE THE MODEL

-- I've combined them into 1 LocalScript, so this is the full script here!
local camera = workspace.CurrentCamera -- We're placing the player's camera as a variable.
local cameraCFrame = Vector3.new(785.252502, 26.7999554, -367.648529)
local cameraFocus = Vector3.new(784.095642, 26.3445187, -366.081909)
local introUI = script.Parent -- Defining the text objects
local playButton = introUI.PlayButton
local creditButton = introUI.CreditButton
local shopButton = introUI.ShopButton
local inventoryButton = introUI.InventoryButton
local TweenService = game:GetService("TweenService") -- This tween stuff will apply to scripting the play button!
local tweeningInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0)
local function hoverEffect(object) -- Make function for it to move a bit.
	local originalPosition = object.Position
	object.MouseEnter:Connect(function()
		object:TweenPosition((originalPosition + UDim2.new(.015, 0, 0, 0)), "Out", "Sine", .1, true)
	end)
	object.MouseLeave:Connect(function()
		object:TweenPosition((originalPosition), "Out", "Sine", .1, true)
	end)
end

-- This part helps apply the hover effect scripted onto the button!
hoverEffect(playButton)
hoverEffect(creditButton)
hoverEffect(shopButton)
hoverEffect(inventoryButton)

--Time to script the play portion!
playButton.MouseButton1Click:Connect(function()
	local fading = introUI.FadeScreen --This is my frame that was transparent.
	local fadeTweenOpaque = TweenService:Create(fading, tweeningInfo, {BackgroundTransparency = 0})
	local fadeTweenTransparent = TweenService:Create(fading, tweeningInfo, {BackgroundTransparency = 1})
	fadeTweenOpaque :Play()
	wait(10) -- Abitrary number, change to what you wish.
	camera.CameraType = Enum.CameraType.Custom -- Change the camera back to player control.
	for _, object in pairs(introUI:GetChildren()) do -- We're gonna delete everything, but the fading part, as we don't need them anymore (for this tutorial)
		if object ~= fading then
			object:Destroy()
		end
	end
	fadeTweenTransparent:Play()
end)

workspace:WaitForChild(tostring(camera)) -- Our camera stuff from before
wait(.1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(cameraCFrame, cameraFocus)

BTW, THIS MODEL ISN’T MINE NOR THE DEVELOPERS
This model is made by @Lugical

CREDITS TO YOU, THE TEAM IS REALLY GRATEFULL.

2 Likes
-- I've combined them into 1 LocalScript, so this is the full script here!
local loadingfinished=false
local character=game.Players.LocalPlayer.Character or nil

local camera = workspace.CurrentCamera -- We're placing the player's camera as a variable.
local cameraCFrame = Vector3.new(785.252502, 26.7999554, -367.648529)
local cameraFocus = Vector3.new(784.095642, 26.3445187, -366.081909)
local introUI = script.Parent -- Defining the text objects
local playButton = introUI.PlayButton
local creditButton = introUI.CreditButton
local shopButton = introUI.ShopButton
local inventoryButton = introUI.InventoryButton
local TweenService = game:GetService("TweenService") -- This tween stuff will apply to scripting the play button!
local tweeningInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0)
local function hoverEffect(object) -- Make function for it to move a bit.
	local originalPosition = object.Position
	object.MouseEnter:Connect(function()
		object:TweenPosition((originalPosition + UDim2.new(.015, 0, 0, 0)), "Out", "Sine", .1, true)
	end)
	object.MouseLeave:Connect(function()
		object:TweenPosition((originalPosition), "Out", "Sine", .1, true)
	end)
end

-- This part helps apply the hover effect scripted onto the button!
hoverEffect(playButton)
hoverEffect(creditButton)
hoverEffect(shopButton)
hoverEffect(inventoryButton)

--Time to script the play portion!
playButton.MouseButton1Click:Connect(function()
	local fading = introUI.FadeScreen --This is my frame that was transparent.
	local fadeTweenOpaque = TweenService:Create(fading, tweeningInfo, {BackgroundTransparency = 0})
	local fadeTweenTransparent = TweenService:Create(fading, tweeningInfo, {BackgroundTransparency = 1})
	fadeTweenOpaque :Play()
	wait(10) -- Abitrary number, change to what you wish.
	loadingfinished=true
	if character then
		if character:FindFirstChild('Humanoid') then
			character.Humanoid.WalkSpeed=16 -- DEFAULT WalkSpeed
		end
	end
	camera.CameraType = Enum.CameraType.Custom -- Change the camera back to player control.
	for _, object in pairs(introUI:GetChildren()) do -- We're gonna delete everything, but the fading part, as we don't need them anymore (for this tutorial)
		if object ~= fading then
			object:Destroy()
		end
	end
	fadeTweenTransparent:Play()
end)

workspace:WaitForChild(tostring(camera)) -- Our camera stuff from before
wait(.1)
if character then
	if character:FindFirstChild('Humanoid') then
		character.Humanoid.WalkSpeed=0 
	end
else
	game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
		if loadingfinished==false then 
		        local h=char:WaitForChild('Humanoid')
			h.WalkSpeed=0
		end
	end)
end
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(cameraCFrame, cameraFocus)

try this

1 Like

Wow thank you! By the way, I’m a big fan!

1 Like

I always use UserInputService and sink all player input using ContextActionService:

--=================================================================================
local UserInputService = game:GetService("UserInputService");
local ContextActionService = game:GetService("ContextActionService");
local FREEZE_PLAYER = "FreezePlayer";

--=================================================================================
function actionSink()

	-- sink all the players actions using the Enum list
	return Enum.ContextActionResult.Sink;

end

--=================================================================================
local function freezeAction()
	
	-- hide joystick and, freeze user input...
	UserInputService.ModalEnabled = not UserInputService.ModalEnabled;
	-- sink all player actions
	ContextActionService:BindAction(FREEZE_PLAYER,
		actionSink,false,unpack(Enum.PlayerActions:GetEnumItems()));
	
end
--=================================================================================
local function unFreeze()
	
	-- unfreeze the player and show joystick again
	UserInputService.ModalEnabled = not UserInputService.ModalEnabled;
	-- remove action sink
	ContextActionService:UnbindAction(FREEZE_PLAYER);
		
end
--=================================================================================
-- EOF..
--=================================================================================
1 Like

Thank you very much for the effort! I’ve learned alot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.