Okay so I am working on a tcg oriented game, and Im currently working on a way to purchase card packs.
- Im using a Proximity Prompt for the Cashier
- Im using a remote event to bring up the dialogue
My problem is that I dont know how Im going to detect when the player has clicked “Purchase” through the dialogue box.
Proximity Prompt Code:
local dialogue_remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):FindFirstChild("Dialogue")
local db = false
local cost = 0
local slides = {
[1] = "That will be $"..tostring(cost),
[2] = "Thanks for shopping!"
}
local interaction_text = {
[1] = "Purchase",
[2] = "Bye!"
}
script.Parent.Triggered:Connect(function(plr)
cost = 0
if db == false then
db = true
for _, item in pairs(plr.Backpack:GetChildren()) do
if item:IsA('Tool') then
local toolCost = item:GetAttribute("Cost")
cost += toolCost
continue
end
end
slides[1] = "That will be $"..tostring(cost)
print(cost)
dialogue_remote:FireClient(plr, slides, interaction_text)
task.wait(1)
db = false
end
end)
Dialogue Script (somewhat modular):
script.Parent.Enabled = false
local dialogue_remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):FindFirstChild("Dialogue")
local plr = game.Players.LocalPlayer
local ui = script.Parent:FindFirstChild("Background")
ui.Position = UDim2.new(0.25, 0,1.25, 0)
local next_button = ui:FindFirstChild("Next")
local exit_button = ui:FindFirstChild("X")
local chat = ui:FindFirstChild("TextBg"):FindFirstChild("Chat")
local currentSlide = 1
local open_db = false
local db = false
local slides = {}
local interaction_text = {}
local function close()
ui:TweenPosition(UDim2.new(0.25, 0,1.25, 0), Enum.EasingDirection.Out,Enum.EasingStyle.Back,0.5,false)
task.wait(1)
open_db = false
script.Parent.Enabled = false
end
local function updateText()
if currentSlide >= (#slides + 1) then
close()
else
next_button.Text = interaction_text[currentSlide]
for i = 1, #(slides[currentSlide]) do
chat.Text = string.sub(slides[currentSlide],1,i)
task.wait(0.025)
end
end
end
dialogue_remote.OnClientEvent:Connect(function(Cslides, Cinteraction_text)
if open_db == false then
open_db = true
currentSlide = 1
script.Parent.Enabled = true
ui:TweenPosition(UDim2.new(0.25, 0,0.79, 0), Enum.EasingDirection.Out,Enum.EasingStyle.Back,0.5,false)
slides = Cslides
interaction_text = Cinteraction_text
updateText()
end
end)
next_button.MouseButton1Click:Connect(function()
if db == false then
db = true
currentSlide += 1
updateText()
task.wait(0.5)
db = false
end
end)
exit_button.MouseButton1Click:Connect(function()
close()
end)