I have a part that if touched, awards the player who touched it some cash. I am stuck trying to tween the GUI I have made onto the screen then back of again. Please help!!!

--Basically checks if the toucher of the button is a player, then adds money to that player.

local ting = 0 --debouncer

local gui = game.StarterGui.ParkourCompleted.Main


function onTouched(hit)

	if ting == 0 then --debounce check
	ting = 1 --activate debounce
	local check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

	if check ~= nil then --If a human is found, then

		local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
		local stats = user:WaitForChild("leaderstats") --Find moneyholder

		if stats ~= nil then --If moneyholder exists then
			local cash = stats:findFirstChild("Cash") --Get money
			cash.Value  = cash.Value +100 --increase amount of money by the number displayed here (100)
			gui:TweenPosition(UDim2.new(0.306, 0,0.395, 0))
			user:LoadCharacter()
			gui:TweenPosition(UDim2.new(0.247, 0,-10, 0))
			wait(30) --wait-time before button works again
		end

	end

	ting = 0 --remove debounce
	end

end

script.Parent.Touched:connect(onTouched)

4 comments

0

this is a script, so it cannot change things that are local like the playergui

0

So if I changed the scipt to a Local Scipt, would it work?

0

change line 5 to the script.Parent version of the path

0

Thank you soooo much!!!