Your correct, my mistake ill see how to fix it
How you gonna mark that as the solution when that’s what I told you to do
because it’s the literal solution, not what the solution is
Anybody can implement the solution and take credit for it . Anyways, I was working on refactoring your code, so I was not able to make an example in time. Here’s the refactor:
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local DialogHitboxes = workspace.Touchactivaters -- Please capitalize the A and consider a more meaningful name.
local Dialoges = require(script.Dialoges) -- You should abstract your table to a ModuleScript.
local RemoteEvents = ReplicatedStorage.RemoteEvents
local Subtitles = RemoteEvents.Subtitles
local storyStage = "Tutorial"
local storySubtage = 1
local function onLivingPlayerTouched(part: BasePart, callback: (player: Player, otherPart: BasePart) -> ()): RBXScriptConnection
return part.Touched:Connect(function(otherPart: BasePart)
local character = otherPart.Parent :: Model
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health <= 0 then
return
end
local player = Players:GetPlayerFromCharacter(character)
if not player then
return
end
callback(player, otherPart)
end)
end
local function tryGetDialoge(dialogeName: string): Dialoges.Dialoge? -- Export a type to improve auto-completion.
local stageDialogs = Dialoges[storyStage]
if not stageDialogs then
warn(`No stage dialoges exist for story stage "{storyStage}".`)
return
end
local dialoge = stageDialogs[storySubtage]
if not stageDialogs then
warn(`No sub-stage dialoges exist for story sub-stage "{storySubtage}"`)
return
end
return dialoge
end
local function tryStartDialoge(hitbox: BasePart)
local dialoge = tryGetDialoge(hitbox.Name)
if not dialoge then
return
end
Subtitles:FireAllClients(dialoge.Speaker, dialoge.Text, dialoge.Color)
storySubtage += 1
hitbox:Destroy() -- Does not appear necessary to keep this around. Clean up event memory.
end
local function tryRegisterDialogeHitbox(hitbox: BasePart)
if not hitbox:IsA("BasePart") then
return
end
onLivingPlayerTouched(hitbox, function()
tryStartDialoge(hitbox)
end)
end
for _, dialogeHitbox in DialogHitboxes:GetChildren() do
tryRegisterDialogeHitbox(dialogeHitbox)
end
DialogHitboxes.ChildAdded:Connect(tryRegisterDialogeHitbox)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.