MouseClick1Down:Connect not working

instead of doing
local button = game.StarterGui.ScreenGui.Frame.ImageButton

do something like
local button = script.Parent
local textBox = button.Parent:WaitForChild(“Frame”)

Because like in the post above said, you’re referencing the object in the starter gui and not the local player’s gui, which is causing it to not work

3 Likes

???
Each player has a different GUI

Try using a local script and using the local players gui, or put a script into the GUI.

2 Likes
local Discord = require(11780461670)
local button = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.ImageButton
local textBox = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextBox

Discord.SetWebhook("https://discord.com/api/webhooks/1259110789449650226/C7IYPeH1vnOSZUTPizKk7aGiWbOyjq32CqlcZyhaWmQJtsK9HCKrAXPUTRFu_0JHCWHW")

button.MouseButton1Down:Connect(function()
	print("does it work? yes it does!")
	local input = textBox.Text
	print(input)
	textBox.Text = ""
	Discord.Embed("", input, "A new submission has been made.", "0xF57D34")
end)

This might take a remote event which is fairly easy to code if you want this to interact with the server.

1 Like

Took me a while to figure out the coding on that, hopefully, I have the event and stuff set up right.

What do I do with this?

2 Likes

Is your script local or server?
Also where is your script located?

1 Like

The script in ServerScriptService is a server script, and the script in the ImageButton that fires the remote event is a local script.

1 Like

So what you need to do is connect to the event in the serverscript such as this

local Event = event_path_here

function OnEvent()
    put_code_here
end)

Event.OnServerEvent:Connect(OnEvent)

Then on the client, fire the code on the server from the button when being clicked:

local Button = script.Parent
local Event = event_path_here

Button.Activated:Connect(function()
	Event:FireServer()
end)
1 Like

I’m still getting the same error, the problem is the PlayerGui path for the ImageButton / TextBox.

1 Like

If the script is located in ServerScriptService it might cause a bit of trouble, we can use a remote event to send the infornmation.

Local script

-- VARIABLES
local RemoteEvent = -- Place of remote event
local Discord = require(11780461670)
local button = script.Parent
local textBox = script.Parent:WaitForChild('textBox')

Discord.SetWebhook("https://discord.com/api/webhooks/1259110789449650226/C7IYPeH1vnOSZUTPizKk7aGiWbOyjq32CqlcZyhaWmQJtsK9HCKrAXPUTRFu_0JHCWHW")

-- FUNCTIONS
button.MouseButton1Down:Connect(function()
    local input = textBox.Text
    RemoteEvent:FireServer(Input)
end)

Server Script

local RemoteEvent = -- Place of remote event

RemoteEvent.OnServerEvent:Connect(Function(Player, Input)
    print("does it work? yes it does!")
	print(input)
	textBox.Text = ""
	Discord.Embed("", input, "A new submission has been made.", "0xF57D34")
end)

Idk if this will work, I usually code with a auto correct feature and I don’t have a full scope of what this is supposed to do.

You could also put the server script into the player gui if you don’t want to separate them into two different scripts.

Sorry I should’ve read your code more clearly the first time. Let me give you some code you can take:

Create a remote function in replicated storage simply using the + icon like you did before when adding scripts.

-- Do this in a local script
local RF = game.ReplicatedStorage.RemoteFunction
local Discord = RF:InvokeServer()
local button = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")Frame.ImageButton
local textBox = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.TextBox

Discord.SetWebhook("https://discord.com/api/webhooks/1259110789449650226/C7IYPeH1vnOSZUTPizKk7aGiWbOyjq32CqlcZyhaWmQJtsK9HCKrAXPUTRFu_0JHCWHW")

button.MouseButton1Down:Connect(function()
	print("does it work? yes it does!")
	local input = textBox.Text
	print(input)
	textBox.Text = ""
	Discord.Embed("", input, "A new submission has been made.", "0xF57D34")
end)
-- Do this in the script in serverscriptservice
local RF = game.ReplicatedStorage.RemoteFunction
RF.OnServerInvoke = function(plr)
local Discord = require(11780461670)
return Discord
end

Hopefully this works but I may be wrong. Test it out.

By the way I changed it a bit sorry, so copy and paste it again.

2 Likes

Does the local script stay under the ImageButton? I’m getting an error thrown regarding line 13 and I believe it’s because I’m placing the local script wrong.

Edit: I copy pasted the new script, it’s still giving me this error.

1 Like

I think this will fix that error.

Copy paste it again srry.

Sorry, it didn’t have any effect. I’m also stupid and forgot to tell you line 13 was the Discord.SetWebhook thing.

Btw, you forgot a dot in between WaitForChild("ScreenGui") and Frame.ImageButton. :slight_smile:

Okay I made a mistake again, this time it should work.

Add a remote event into replicatedstorage instead of a remote function and use this new code.

-- Paste this in the local script
local RE = game.ReplicatedStorage.RemoteEvent
local button = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.ImageButton
local textBox = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.TextBox

button.MouseButton1Down:Connect(function()
	RE:FireServer(textbox)
end)
-- Paste this in the script in serverscriptservice
local Discord = require(11780461670)
local RE = game.ReplicatedStorage.RemoteEvent

Discord.SetWebhook("https://discord.com/api/webhooks/1259110789449650226/C7IYPeH1vnOSZUTPizKk7aGiWbOyjq32CqlcZyhaWmQJtsK9HCKrAXPUTRFu_0JHCWHW")

RE.OnServerEvent:Connect(function(plr, textbox)
textBox.Text = ""
Discord.Embed("", input, "A new submission has been made.", "0xF57D34")
end)
1 Like

Thank you so much! After a bit of trial and error with HTTP requests, I managed to get the script working:

-- local script
local RE = game.ReplicatedStorage.RemoteEvent
local button = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.ImageButton
local textBox = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame.TextBox

button.MouseButton1Down:Connect(function()
	RE:FireServer(textBox)
end)
-- serverscriptservice script
local RE = game.ReplicatedStorage.RemoteEvent

local url = "https://discord.com/api/webhooks/1259110789449650226/C7IYPeH1vnOSZUTPizKk7aGiWbOyjq32CqlcZyhaWmQJtsK9HCKrAXPUTRFu_0JHCWHW"
local http = game:GetService("HttpService")

RE.OnServerEvent:Connect(function(plr, textBox)
	local textInput = textBox.Text
	local data = {
		['embeds'] = {{
			['title'] = textInput,
			['description'] = "A new submission has been made: **"..textInput.."**",
			['color'] = tonumber(0xF57D34)
			}
		}
	}
	local finalData = http:JSONEncode(data)
	http:PostAsync(url, finalData)
	textBox.Text = ""
end)

Side question, do you have any idea why the script can’t grab the player’s textbox input? If you help me solve this too, I’ll be super thankful.
image

hey this is off topic but … from my knowledge, discord ban roblox from using their api unless you are in studio. This is because people made games allowing users under 13 to use discord without a discord acc through a game on roblox

2 Likes

Good to know, thanks! I switched to a working proxy instead.

1 Like

To be honest i’m not an expert at using httpservice lol, all I knew was that you have to require from the server instead of the client. So I’m not sure.

1 Like

It’s all good now, I resolved the issue here. :slight_smile:

Edit: Oops, wrong link. Here’s the actual one.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.