Whats wrong with this code?

This code I made for a webhook feature is not working when on clicked. Why is that?
The GUI original position is - {-0.252, -300},{0.735, -300}
Script:

local click = script.Parent.Parent.ClickDetector
click.RightMouseClick:Connect(function()
	open = not open
	if open then
		feedbackMain:TweenPosition(UDim2.new(-0.252, -300,0.735, -300),"Out","Quint",0.3,true)
	else
		feedbackMain:TweenPosition(UDim2.new(0, 42,0, 12),"Out","Quint",0.3,true)
	end
end)
1 Like

What is feedbackMain defined as

2 Likes

Are you using a LocalScript or Script, and where is the script located at?

Remember that a LocalScript does not work when in Workspace, so if it is located in Workspace, I suggest moving it into the ScreenGui where feedbackMain is located at, so the code would look like this:

-- As example: workspace.SendFeedback.ClickDetector
local click = path.to.part.ClickDetector
click.RightMouseClick:Connect(function()
	open = not open
	if open then
		feedbackMain:TweenPosition(UDim2.new(-0.252, -300,0.735, -300),"Out","Quint",0.3,true)
	else
		feedbackMain:TweenPosition(UDim2.new(0, 42,0, 12),"Out","Quint",0.3,true)
	end
end)

(I can’t guarantee that the above will work since we do not know more details about what type of script you are using and where it is located.)

1 Like

Yes its in a screenGUI in workspace
plans

local feedbackMain = script.Parent.FeedbackMain

Try to structure it like this:
image
And change the ControlScript to following code:

local open = false
local feedbackMain = script.Parent.FeedbackMain
local click = workspace.OpenFeedback.ClickDetector

click.RightMouseClick:Connect(function(playerWhoClicked)
	if not playerWhoClicked == game.Players.LocalPlayer then return end 
	open = not open
	if open then
		feedbackMain:TweenPosition(UDim2.new(-0.252, -300,0.735, -300),"Out","Quint",0.3,true)
	else
		feedbackMain:TweenPosition(UDim2.new(0, 42,0, 12),"Out","Quint",0.3,true)
	end
end)

What I changed is:

  • Placed the ScreenGui inside of StarterGui making it unique for all Players
  • Changed the code in ControlScript so it gets the OpenFeedback Part and then binds the RightMouseButton Event to the function and check inside of the function if the player who clicked is actually the local player.
3 Likes

Putting "Out" and "Quint" as EasingDirection and EasingStyle is bad practice.

Use Enum.EasingDirection.Out and Enum.EasingStyle.Quint instead.