Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to sync money added and gui message?

local frame = script.Parent.Frame
local button = script.Parent.TextButton
local moneycount = game.Players.LocalPlayer.MoneyCount

function getMoney()
	frame:TweenPosition(UDim2.new(0.5,-100,0.5,-25),'Out','Quint',.5)
	wait(.75)
	frame:TweenPosition(UDim2.new(0.5,-100,10,-25),'In','Quint',.5)
end

local function addMoney()
	wait(.5)
	moneycount.Value = moneycount.Value + 1
	wait(1.25)
end

button.MouseButton1Click:Connect(addMoney)
button.MouseButton1Click:Connect(getMoney)

So this script is for whenever I click a button it sends up a message saying you earned money and it adds money to an IntValue. What I want to do is make sure that everytime the message comes up money is added to your IntValue, but when I repeatedly click the button, it adds money and the message doesn't pop up. Can somebody help me?

2 answers

I think the problem is because you're calling 2 functions!!?!?!??!

Try the following:

local frame = script.Parent.Frame
local button = script.Parent.TextButton
local moneycount = game.Players.LocalPlayer.MoneyCount

--Transforming 2 functions into 1
button.MouseButton1Click:connect(function()
	frame:TweenPosition(UDim2.new(0.5,-100,0.5,-25),'Out','Quint',.5)
	wait(.5)
	moneycount.Value = moneycount.Value + 1
	wait(.25)
	frame:TweenPosition(UDim2.new(0.5,-100,10,-25),'In','Quint',.5)
	wait(.5) --I don't understand why do you need this wait() in the end, I'll leave it there, but later, you might want to remove it. *might*
end)

Ok, so this should be enough. If it works, please mark as the answer!

As always, keep the good scripting!

1 comment

0

Still not working. When I click the button repeatedly, it adds money, but the message doesn't show up at the same time. I want to make sure that the money only gets added when the message pops up.

I am not sure if this is the issue, BUT, I'm not sure if you can have multiple events tied to one listener.

local frame = script.Parent.Frame
local button = script.Parent.TextButton
local moneycount = game.Players.LocalPlayer.MoneyCount

function getMoney()
    frame:TweenPosition(UDim2.new(0.5,-100,0.5,-25),'Out','Quint',.5)
    wait(.75)
    frame:TweenPosition(UDim2.new(0.5,-100,10,-25),'In','Quint',.5)
end

function addMoney()
    wait(.5)
    moneycount.Value = moneycount.Value + 1
    wait(1.25)
end

function stuff()
	addMoney() -- Add the money
	getMoney() -- Tween a gui
end
button.MouseButton1Click:Connect(stuff) -- Trigger a new function

This discussion is preserved as it was. New answers, comments, and votes are closed.