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)