Area Gui Problem

So my current problem is that sometimes the reading time is not at 10 or the player doesn’t have enough time to read the description. I personally don’t know what I did wrong here, but maybe you have a tip for me as to whether I did something wrong. I’ve put my script below. If you notice a mistake or something that could cause errors, please let me know.

local player = game.Players.LocalPlayer
local areas = workspace.Areas
local rs = game:GetService("ReplicatedStorage")
local r = game:GetService("RunService")
local ts = game:GetService("TweenService")
local sounds = rs.Sounds
local music = rs.Music
local currentArea = nil
local currentSound = nil
local currentMusic = nil
local lastMusic = nil
local lastSound = nil
local t1
local t2
local t3
local main = script.Parent
local template = main.template
local currenttemplate = nil
local data_by_area = {
	
	[areas:WaitForChild("MM1")] = {
		["Name"] = "Mysterious Mountain",
		["Description"] = "A mysterious and peaceful mountain - is this the area<br />where the meteorit crashed 150 years ago?",
		["Ambience"] = sounds.Birds,
		["Music"] = music.Dreamcatcher,
	},
	[areas:WaitForChild("MR2")] = {
		["Name"] = "Mysterious Ruin",
		["Description"] = "A mysterious ruin - you feel a streange power,<br />you might open the door with your friend and explore it.",
		["Ambience"] = nil,
		["Music"] = music.mysteriousruin
	}
	
}

local function isPlayerInArea(area, ppart)
	
	local areaRegion = Region3.new(area.Position - (area.Size / 2.1), area.Position + (area.Size / 2.1))
	local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(areaRegion, {ppart})
	
	for _, part in ipairs(partsInRegion) do
		
		if part == ppart then
			
			return true
			
		end
		
	end
	
	return false
	
end

local function showAreaInfo(data)
	
	if currenttemplate ~= nil then currenttemplate:Destroy() end
	
	currenttemplate = template:Clone()
	currenttemplate.Parent = main
	
	currenttemplate.Line.Size = UDim2.new(0, 0, 0.005, 0)
	currenttemplate.NameHolder.areaNameShadow.Position = UDim2.new(0.505, 0, 1.5, 0)
	currenttemplate.Description.areaDescription.Position = UDim2.new(0.5, 0, -0.5, 0)
	currenttemplate.NameHolder.areaNameShadow.Text = data["Name"]
	currenttemplate.NameHolder.areaNameShadow.areaName.Text = data["Name"]
	currenttemplate.Description.areaDescription.Text = data["Description"]
	repeat task.wait() currenttemplate.readingTime.Value = 10 until currenttemplate.readingTime.Value == 10
	
	ts:Create(currenttemplate.Line, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0, 0.005, 0)}):Play()
	task.wait(0.3)
	ts:Create(currenttemplate.Line, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0, 0.035, 0)}):Play()
	task.wait(0.3)
	
	ts:Create(currenttemplate.NameHolder.areaNameShadow, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(0.505, 0, 0.5, 0)}):Play()
	ts:Create(currenttemplate.Description.areaDescription, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
	
	repeat task.wait() currenttemplate.readingTime.Value = 10 until currenttemplate.readingTime.Value == 10
	
	while currenttemplate.readingTime.Value > 0 do
		
		task.wait(0.1)
		
		currenttemplate.readingTime.Value = currenttemplate.readingTime.Value - 0.1
		
	end
	
	ts:Create(currenttemplate.NameHolder.areaNameShadow, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Position = UDim2.new(0.505, 0, 1.5, 0)}):Play()
	ts:Create(currenttemplate.Description.areaDescription, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Position = UDim2.new(0.5, 0, -0.5, 0)}):Play()
	task.wait(0.3)
	
	ts:Create(currenttemplate.Line, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Size = UDim2.new(1, 0, 0.005, 0)}):Play()
	task.wait(0.3)
	
	ts:Create(currenttemplate.Line, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = UDim2.new(0, 0, 0.005, 0)}):Play()
	task.wait(0.3)
	
	currenttemplate:Destroy()
	
end

rs.startAreas.OnClientEvent:Connect(function()
	
	while wait(0.1) do
		
		local char
		local part

		if player then

			pcall(function()

				char = player.Character

			end)

			if char then

				part = char:WaitForChild("HumanoidRootPart")

			end

			if part then

				for area, data in pairs(data_by_area) do

					if isPlayerInArea(area, part) then

						if currentArea ~= area then

							currentArea = area

							spawn(function()						
								
								if currenttemplate then
									
									currenttemplate:Destroy()
									
								end
								
								showAreaInfo(data)

							end)

							if currentMusic then

								lastMusic = currentMusic
								currentMusic = data["Music"]

								if lastMusic then

									lastMusic:Stop()

								end

								if currentMusic then

									currentMusic:Play()

								end

							else

								currentMusic = data["Music"]

								if currentMusic then

									currentMusic:Play()

								end


							end

							if currentSound then

								lastSound = currentSound
								currentSound = data["Ambience"]

								if lastSound then

									lastSound:Stop()

								end

								if currentSound then

									currentSound:Play()

								end

							else

								currentSound = data["Ambience"]

								if currentSound then

									currentSound:Play()

								end

							end

						end

					end

				end

			end

		end
		
	end

end)

I’ve fixed it :slight_smile: for everyone who wanna use it too:

Local Script of the GUI

local player = game.Players.LocalPlayer
local areas = workspace.Areas
local rs = game:GetService("ReplicatedStorage")
local sounds = rs.Sounds
local music = rs.Music
local createTemplate = require(rs.actions.createAreaTemplate)
local setAreaData = require(rs.actions.setAreaData)
local tweengui = require(rs.actions.TweenGui)
local currentArea = nil
local currentSound = nil
local currentMusic = nil
local lastMusic = nil
local lastSound = nil
local main = script.Parent
local template = main.template
local currenttemplate = nil
local data_by_area = {
	
	[areas:WaitForChild("MM1")] = {
		["Name"] = "Mysterious Mountain",
		["Description"] = "A mysterious and peaceful mountain - is this the area<br />where the meteorit crashed 150 years ago?",
		["Ambience"] = sounds.Birds,
		["Music"] = music.Dreamcatcher,
	},
	[areas:WaitForChild("MR2")] = {
		["Name"] = "Mysterious Ruin",
		["Description"] = "A mysterious ruin - you feel a streange power,<br />you might open the door with your friend and explore it.",
		["Ambience"] = nil,
		["Music"] = music.mysteriousruin
	}
	
}

local function isPlayerInArea(area, ppart)
	
	local areaRegion = Region3.new(area.Position - (area.Size / 2.1), area.Position + (area.Size / 2.1))
	local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(areaRegion, {ppart})
	
	for _, part in ipairs(partsInRegion) do
		
		if part == ppart then
			
			return true
			
		end
		
	end
	
	return false
	
end

local function showAreaInfo(data)
	
	currenttemplate = createTemplate(template, main)
	
	setAreaData(currenttemplate, data)
	
	if tweengui(currenttemplate.Line, UDim2.new(1,0,0.005,0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, "Size") then
		
		if tweengui(currenttemplate.Line, UDim2.new(1,0,0.035,0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, "Size") then
			
			if tweengui(currenttemplate.NameHolder.areaNameShadow, UDim2.new(0.505, 0, 0.5, 0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, "Position") and tweengui(currenttemplate.Description.areaDescription, UDim2.new(0.5,0,0.5,0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, "Position") then
				
				if tweengui(currenttemplate.readingTime, 0, 10, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, "NumberValue") then
					
					if tweengui(currenttemplate.Description.areaDescription, UDim2.new(0.5, 0, -0.5, 0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In, "Position") and tweengui(currenttemplate.NameHolder.areaNameShadow, UDim2.new(0.505,0,1.5,0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In, "Position") then
						
						if tweengui(currenttemplate.Line, UDim2.new(1,0,0.005,0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In, "Size") then
							
							if tweengui(currenttemplate.Line, UDim2.new(0,0,0.005,0), 0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In, "Size") then
								
								currenttemplate:Destroy()
								
							end
							
						end
						
					end
					
				end
				
			end
			
		end
		
	end
	
end

rs.startAreas.OnClientEvent:Connect(function()
	
	while wait(0.1) do
		
		local char
		local part

		if player then

			pcall(function()

				char = player.Character

			end)

			if char then

				part = char:WaitForChild("HumanoidRootPart")

			end

			if part then

				for area, data in pairs(data_by_area) do

					if isPlayerInArea(area, part) then

						if currentArea ~= area then

							currentArea = area

							spawn(function()						
								
								if currenttemplate then
									
									currenttemplate:Destroy()
									
								end
								
								showAreaInfo(data)

							end)

							if currentMusic then

								lastMusic = currentMusic
								currentMusic = data["Music"]

								if lastMusic then

									lastMusic:Stop()

								end

								if currentMusic then

									currentMusic:Play()

								end

							else

								currentMusic = data["Music"]

								if currentMusic then

									currentMusic:Play()

								end

							end

							if currentSound then

								lastSound = currentSound
								currentSound = data["Ambience"]

								if lastSound then

									lastSound:Stop()

								end

								if currentSound then

									currentSound:Play()

								end

							else

								currentSound = data["Ambience"]

								if currentSound then

									currentSound:Play()

								end

							end

						end

					end

				end

			end

		end
		
	end

end)

createTemplate Module

return function(template, main)
	
	local ct = template:Clone()
	
	ct.Name = "Area"
	
	ct.Line.Size = UDim2.new(0, 0, 0.005, 0)
	ct.NameHolder.areaNameShadow.Position = UDim2.new(0.505, 0, 1.5, 0)
	ct.Description.areaDescription.Position = UDim2.new(0.5, 0, -0.5, 0)
	
	ct.Parent = main
	
	return ct
	
end

setAreaData Module

return function(ct, data)
	
	ct.NameHolder.areaNameShadow.Text = data["Name"]
	ct.NameHolder.areaNameShadow.areaName.Text = data["Name"]
	ct.Description.areaDescription.Text = data["Description"]
	ct.readingTime.Value = 10
	
end

Tween Module

local ts = game:GetService("TweenService")

return function(ui, enddata, time, style, direction, data)
	
	local tween
	
	if data == "Size" then
		
		tween = ts:Create(ui, TweenInfo.new(time, style, direction), {Size = enddata})
		
	elseif data == "Transparency" then
		
		tween = ts:Create(ui, TweenInfo.new(time, style, direction), {Transparency = enddata})
		
	elseif data == "Position" then
		
		tween = ts:Create(ui, TweenInfo.new(time, style, direction), {Position = enddata})
		
	elseif data == "NumberValue" then
		
		tween = ts:Create(ui, TweenInfo.new(time, style, direction), {Value = enddata})
		
	end
	
	tween:Play()
	tween.Completed:Wait()
	
	return true
	
end

bc not everything is happening in one script it should increase the performance and fix the issue with the task.wait() :smiley:

Btw you spelled strange wrong

Nice work Though!

oh thanks :smiley: i didnt saw it xD

1 Like

oh btw @Sicko_Poofy here is a picture of my Project :sunglasses:

Oml yo thats sick what game are you making?

its gonna be an Mage Fantasy Adventure MMORPG :smiley:

1 Like

Tell me when its playable I’ll try it!

well i could invite you to my Game Studio Server and you’ll know it!

1 Like

Quick question btw could you try to solve a problem i’m having?

heres the post

well if you had some code uploaded you might get more help. otherwise we cant pretty help you.

Ok I’ll send some rn

So im trying to make the ball be kicked just randomly by no one but I want it to be slow whenit in the air

function Round.KickBall()
	wait(4)
	workspace.Football.Anchored = false
	
	local receivingTeleports = workspace.Teleports.ReceivingSide:GetChildren()
	local randomTeleport = receivingTeleports[math.random(1, #receivingTeleports)]

	local BodyPosition = Instance.new("BodyPosition")
	BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)  -- Set max force for movement
	BodyPosition.D = 1500  -- The damping, controls how fast it stops moving
	BodyPosition.P = 4000   -- The force applied to reach the target position
	BodyPosition.Position = Vector3.new(randomTeleport.Position.X ,100,randomTeleport.Position.Z)
	
	BodyPosition.Parent = workspace.Football
	
	game:GetService("Debris"):AddItem(BodyPosition, .01)
end

also it’s in a module script which connects to a round system

hmm i have no idea i never used an “Kick football” function :V i allways use tweens or cframe.

Ok i will try tweening it with parts

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