Hello guys. I’ll say right away that the problem is serious. I can’t solve it.
For some reason, exchanging energy for money does not work. Can you find the reason? Even the cancel button doesn’t work. Please watch the video carefully. Option1 Option2 Option3 It doesn’t interact.
scripts Mаin
local Character = nil
game.ReplicatedStorage.Merchant1.Event:Connect(function(item, data, character)
Character = character
script.Parent.Option1.Visible = false
script.Parent.Option2.Visible = false
script.Parent.Option3.Visible = false
script.Parent.Dialogue.Text = "Do you want to exchange energy for money?"
script.Parent.Option1.Text = "Exchange all energy"
script.Parent.Option2.Text = "Exchange 50% energy"
script.Parent.Option3.Text = "No, thanks"
script.Parent.Option1.Visible = true
script.Parent.Option2.Visible = true
script.Parent.Option3.Visible = true
end)
script.Parent.Option1.MouseButton1Click:Connect(function()
local player = game.Players:GetPlayerFromCharacter(Character)
local energyValue = player.leaderstats.Energy.Value
if energyValue > 0 then
local cashValue = player.leaderstats.Cash.Value
local exchangedEnergy = energyValue
player.leaderstats.Cash.Value = cashValue + exchangedEnergy
player.leaderstats.Energy.Value = 0
end
script.Parent.Parent:Destroy()
end)
script.Parent.Option2.MouseButton1Click:Connect(function()
local player = game.Players:GetPlayerFromCharacter(Character)
local energyValue = player.leaderstats.Energy.Value
if energyValue > 0 then
local cashValue = player.leaderstats.Cash.Value
local exchangedEnergy = math.floor(energyValue / 2)
player.leaderstats.Cash.Value = cashValue + exchangedEnergy
player.leaderstats.Energy.Value = energyValue - exchangedEnergy
end
script.Parent.Parent:Destroy()
end)
Decline
local Talked = false
function Talk(Label, Text)
for i = 1, #Text do
Label.Text = string.sub(Text, 1, i)
wait()
end
end
function CreateOptions(Option1Text, Option2Text, Option3Text)
script.Parent.Option1.Visible = true
script.Parent.Option1.Text = Option1Text
script.Parent.Option2.Visible = true
script.Parent.Option2.Text = Option2Text
script.Parent.Option3.Visible = true
script.Parent.Option3.Text = Option3Text
end
while wait() do
if not Talked and not script.Disabled then
Talked = true
Talk(script.Parent.Dialogue, “Do you want to exchange energy for money?”, “Exchange all energy”, “Exchange 50% energy”,“No,Thx”)
CreateOptions(“Exchange all energy”, “Exchange 50% energy”, “No,Thx”)
end
end
script.Parent.Option1.MouseButton1Click:Connect(function()
script.Parent.Parent:Destroy()
end)
script.Parent.Option2.MouseButton1Click:Connect(function()
script.Parent.Parent:Destroy()
end)
script.Parent.Option3.MouseButton1Click:Connect(function()
script.Parent.Parent:Destroy()
end)