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

Expected ')' (to close '(' at line 4), got <eof>?

Hello! I am trying to make a discord webhook that posts a message when someone touches a part. I want the message to include the username of the person at the start. But when I use the code it posts nothing and shows a error in the script. Here is my script:

local http = game:GetService('HttpService')
local part = script.Parent
if part.Touched then
	game.Players.PlayerAdded:connect(function(plr)
	
		local Data = {
			["content"] = plr.Name.." has beaten "..part.Name
		}
		Data = http:JSONEncode(Data)
		http:PostAsync("discord webhook link here (i replaced this because I don't want anyone to use the link.))", Data)
end

This script had the 'end' at the end have a red line underneath. (

) Plus when I tried to, the webhook posted this: 'Players has beaten Mystery Stage' (this was a different script) Here is the second script I had problems with:

local http = game:GetService('HttpService')
local player = game:GetService("Players")
local part = script.Parent
if part.Touched then
		local Data = {
			["content"] = player.Name.." has beaten "..part.Name
		}
		Data = http:JSONEncode(Data)
		http:PostAsync("discord webhook link here (i replaced this because I don't want anyone to use the link.))", Data)
end

Thank you.

3 answers

All you have to do is add a closing bracket to the ‘end’ on line 11 (first script)

and for the second one you haven’t gotten the instance player so it outputs the variable name.

2 comments

0

AstrologicalVI, what do you mean by 'instance player'?

0

Oh sorry I’ve been inactive, for the “Instance player” you only defined the Players Service. In order to fix that all you have to do is: local player = game:GetService(“Players”).LocalPlayer

You just simply forgot to close off the function,

local http = game:GetService('HttpService')
local part = script.Parent
if part.Touched then
    game.Players.PlayerAdded:connect(function(plr)

        local Data = {
            ["content"] = plr.Name.." has beaten "..part.Name
        }
        Data = http:JSONEncode(Data)
        http:PostAsync("discord webhook link here (i replaced this because I don't want anyone to use the link.))", Data)
	end)
end

1 comment

0

Thanks!

Touched is an event so it has to be like part.Touched:Connect(functionName)

You're just checking on who's touching the part, so the game.Players.PlayerAdded is unnecessary. Touched event has a parameter so we can detect if it's the player or not

The whole code looks like this now

local http = game:GetService('HttpService')
local part = script.Parent
	
part.Touched:Connect(function(hit)
	--Check if it's a player
	if hit.Parent:FindFirstChild("Humanoid") then
		--If it is a player, then store that player (workspace) into the plr variable
		local plr = hit.Parent
		
		local Data = {
			["content"] = plr.Name .." has beaten ".. part.Name
		}
		
		Data = http:JSONEncode(Data)
		http:PostAsync("I've used discord webhook before, so I understand :P", Data)
	end
end)

2 comments

0

and Thank you TheBigBro122 too!

0

welcome... If LazerShatters solved your problem, I'd recommend making that the solution

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