Hello, I was wondering how I could fix expected then when parsing if statement got
Can anyone help me?
Is there a missing then after your if?
For example, you might get this error when you do this:
if(true) --Wrong
end
But this will work:
if(true) then --Right
end
Could you share your code thats causing the error?
I believe you might have forgotten to add “then” when writing the “if statement”
Here is my code.
local KeyModule = require(script.Parent:WaitForChild("Game Logic").KeyModule)
game.ReplicatedStorage.DestroyBool.OnServerEvent:Connect(function(player)
if player:FindFirstChild("Value") then
player.Value:Destroy()
player.CharacterAdded:connect(function(char)
char.Humanoid.Died:connect(function()
game.ReplicatedStorage.DestroyTags.OnServerEvent:Connect(function(player)
if player:FindFirstChild("Contestant") then
player.Contestant:Destroy()
elseif game.ReplicatedStorage.DestroyTags.OnServerEvent:Connect(function(player)
if player:FindFirstChild("Piggy") then
player.Piggy:Destroy()
end
KeyModule.DropTools(player,game.Workspace.map,char.HumanoidRootPart.Position)
print("Dropped Tools")
end)
This line:
elseif game.ReplicatedStorage.DestroyTags.OnServerEvent:Connect(function(player)
You forgot then in the end
Add then to this if:
elseif game.ReplicatedStorage.DestroyTags.OnServerEvent:Connect(function(player) then
Another thing, I might be misunderstanding something, but are you sure that’s the right way to check when the event fires?
I’m not sure if thats a right way to use if statement. I doubt you can use events when doing the comparison for if statements. I might be wrong on this.
You are also missing alot of “end” for the code blocks.
How many ends would I be missing?
I think he is trying to check when the event fires, if that’s what he is trying to do, then that’s not the right way.
To check if an event fires, you can do something like this for example:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
print("Function runs")
end)
--Or this:
local function myFunc = function()
print("Function runs")
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(myFunc)
End is missing for the first event, your first if statement, character added event, humanoid died event, destroy tags event, the if statement after destroy tag.