Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

0
AstrologicalVI, what do you mean by 'instance player'? samast2010 0 — 4y
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 AstrologicalVI 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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
0
Thanks! samast2010 0 — 4y
Log in to vote
0
Answered by 4 years ago

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)
0
and Thank you TheBigBro122 too! samast2010 0 — 4y
0
welcome... If LazerShatters solved your problem, I'd recommend making that the solution TheBigBro122 427 — 4y

Answer this question