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

"Expected identifier when parsing expression, got ')' Help? (FIXED BY ME)

Asked by 4 years ago
Edited 4 years ago

I am trying to make a sort of "RPG" type game, I finished rigging a dragon rig that would guide you through the begining but when using a script to change the text if the text said something else (on click) It told me "Expected identifier when parsing expression, got ')'" I will show my script below. (normal script responding to click detector inside model)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Greetings young traveler."

end)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if
        player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text == "Greetings young traveler."
        then player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Fetch me a water bucket."

end)
0
you forgot an end in the if Amiaa16 3227 — 4y
0
Do you mean something like "If end?" ( I dont really use "If" that much so I dont know much about it) O_OIMGONE 9 — 4y

2 answers

Log in to vote
0
Answered by
gskw 1046 Moderation Voter
4 years ago

Let's format your code properly:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Greetings young traveler."
end)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text == "Greetings young traveler." then
        player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Fetch me a water bucket."

end)

The issue here is that if ... then doesn't want to have a single statement for the "then". It takes multiple statements, and the end of the group should be denoted by an end. To fix the syntax error, we can write:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Greetings young traveler."
end)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text == "Greetings young traveler." then
        player:WaitForChild("PlayerGui").ScreenGui.TextLabel.Text = "Fetch me a water bucket."
    end
end)

However, what you have in your code is probably not what you want. Every time the ClickDetector is clicked, both connected functions will be executed (in an unspecified order). This means that the TextLabel's text will be set to one of the two strings, but Roblox makes no guarantee of which string it will be. How would you like the text to change?

Ad
Log in to vote
0
Answered by 4 years ago

To get down how I want the text to change was going to be weird I am kind of lazy so I was going to remove the click detector but then add it back through the "Parent" part of every part and model so you could only click on it again if the parent would be put back so you could only "Talk" to the tutorial dragon again if the click detector was inside of it. It would move the click detector based on if it did an animation ( this animation would happen also when you clicked the dragon) So when you gathered the water bucked by clicking a object it would expediently know and therefor put the click detector back inside the model.

Though I would like the text to change so if you tried to click on the dragon before you actually retrieved the item you are looking for it would ask you to get it again.

Answer this question