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

Why does tweening this GUI only work once on both commands? [SOLVED]

I solved this by checking (on the second function) whether the position was at a Y-Scale coordinate of 400. Thanks to all those who replied.

When I run this, saying "commands" makes the GUIs move out of their position, and saying "commands off" moves them back. If I say "commands" again, the GUIs do not move back to their position. How do I make it move back on saying "commands" again? --Edit, I need this to work only for my character, and it'd be more efficient if I could do it with the same command.

To test it: https://www.roblox.com/games/862131713/Empty-Lot

wait(3)
for i, v in pairs(game.Players:GetPlayers()) do
	--if v.Character.Name == "Sabaist" then
		v.Chatted:connect(function(msg)
			if msg == "Commands" or "commands" then
				for s, h in pairs(script.Parent:GetChildren()) do
					toggle = true
					if h:IsA("TextBox") and toggle == true then
						local const = h.Position.Y.Offset
	h:TweenPosition(UDim2.new(0, 400, 0, const), 'In', 'Bounce', 3)
					toggle = true
				end
				end
			end
			end)
		end

for i, v in pairs(game.Players:GetPlayers()) do
	--if v.Character.Name == "Sabaist" then
		v.Chatted:connect(function(msg)
			if msg == "Commands Off" or "commands off" then
				for s, h in pairs(script.Parent:GetChildren()) do
					if h:IsA("TextBox") and toggle == true then
						local const = h.Position.Y.Offset
	h:TweenPosition(UDim2.new(0, -400, 0, const), 'Out', 'Bounce', 3)
					toggle = true
				end
				end
			end
			end)
		end

1 comment

0

Updated my answer including the edits from your comment

1 answer

Forgive me if I'm wrong (it's been a long day) but I'm pretty sure this script only runs once which would be why it doesn't work as you expect. You'd want to put the two parts of the script you have into functions that call when ever the specific word has been said...

I'll give an example and you can modify as you wish:


game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(msg)
		if player.Name == "Sabaist" then
			if msg == "Commands" then
			for s, h in pairs(script.Parent:GetChildren()) do
				toggle = true
				if h:IsA("TextBox") and toggle == true then
					local const = h.Position.Y.Offset
					h:TweenPosition(UDim2.new(0, 400, 0, const), 'In', 'Bounce', 3)
					toggle = true
				end
			end
		end
	end)
end)

This may or may not work, I haven't tested it.. Reference was taken from here should you want more information


Please accept my answer should this be the working solution!

Feel free to ask any questions about the code and let me know if it doesn't work, I'll see if I can fix it :)

2 comments

0

Yes this is correct, you must get ALL players that join. By using a table at the start will only get the first player who joins since the script is only being ran once. Though, it should be working for that one person if it has worked the first time

0

I forgot to mention that I need this to only work for one person in the game. How would I go about opening and closing the GUIs with only one command? I replaced the first line in Uroxus' example with ~~~~~~~~for i, v in pairs(game.Players:GetPlayers()) do if v.Character.Name == "Sabaist" then~~~~~~~~ Thanks.

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