Module script ony letting a tween run once? Or error in my code?

Hi everyone! I’ve run into a problem… The script you see down there makes a gui frame tween into position when a part is stepped on! The problem is, that it works once but then the tween just doesnt work anymore. Is there a problem with the tween being stored on a module script?

Btw.: there are no errors!

Thanks for you help!

local Toucher = script.Parent
local debounce = false
local Ui
local Tweens

Toucher.Touched:Connect(function(hit)
	
	if not debounce then
		
		local parent = hit.Parent
		
		if parent then
			
			if hit.Parent:FindFirstChild("Humanoid") then
				if hit.Parent.Name ~= "Blacksmith" then
					
					debounce = true
					
					Tweens = require(game.Players[hit.Parent.Name]:WaitForChild("PlayerGui")["Smelt/Craft"].TweenPositions)
					
					Tweens.SelectionIn()
					wait(1)	
					debounce = false
					
				end
			end
		end		
	end
end)

Module Script:

SelectionIn = function()
		
		SelectionUi:TweenPosition(UDim2.new(0.125, 0,0.125, 0),"In","Sine",0.4,false,nil)
		
	end,
	
	SelectionOut = function()
		
		SelectionUi:TweenPosition(UDim2.new(0.125, 0,1.5, 0),"Out","Sine",0.4,false,nil)
		
	end,
	

Something that may work is to reset the position of the Smelt/Craft when it’s finished tweening. If you tween it, and then try to tween it again without reseting the position of the Frame, it will just become visible where it left off after the last tween. So you may want to use a TouchEnded function to reset the position of your Frame so that it can tween again. Hopefully that works and makes sense.

1 Like

Could you provide the ModuleScript as well please?

Did you try putting print statements in each section to see where it stops working?
As @fiveironfan2006 stated, try printing the Position of the GUI frame at the beginning and end of each function call.

yeah i actually tried that! But the script would just run like normal. Even if i put a print statment under the tween thing it was printed normally

wait nevermind… the position is the same as it was before the tween… its 0.125,0,0.125,0 so its invisble

You are using only SelectionIn(), which points to same Udim2 position.

Make sure that when you finish you call the SelectionOut() function.

so the tween opens the selection screen but then you get the option to close it… which is on the ui so its not on the touch function script!

So when you close it on the UI it doesn’t open again after stepping on the part?

1 Like

yep that is exactly the problem lol

You might want to switch that into LocalScript if you’re not doing that already, as it doesn’t seem like it. GUIs should be always handled on the client. You will spare yourself a lot of trouble. Server isn’t able to access player’s GUIs.

1 Like

ok true that ima try that! thanks so far

I agree with @Sougood. I would try that. Another option (maybe more complex and time consuming, but should work) is to use a RemoteEvent. Then you can use FireServer when a player closes the Frame out, and after that call the SelectionOut() function on the module script.

1 Like
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui

local debounce = false

Toucher.Touched:connect(function(hit)
   if not debounce and Player.Character ~= nil then
      if hit:IsDescendantOf(Player.Character)
         debounce = true
         --fill tweening here
         debounce = false
      end
   end
end)

Make sure to use this in LocalScript as GUI coding should be handled on Client side.

1 Like

Ok guys its a deal lol i know why it didnt work lol i had to communicate with the client as well so the position on the server was right but not on the client… i switched to a local script and now it works perfectly! Thank you guys for you help!

2 Likes

No problem, glad you were able to fix it!

1 Like

Not sure if you are looking for this but, i made a modulescripts with some tween animations via serverscript. Might help you.


https://dreahzy.studio/animationloader.html