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

How do you fix the 'then' expected near ',' error?

I have made a script and came across this error;

Players.Player1.PlayerGui.BattleGui.BattleFrame.AttackButton.LocalScript:10: 'then' expected near ','

I can't read errors and I don't know how to fix em, please help!

This is the script;

local button = script.Parent
local SH = script.Parent.Parent.NPCCardFrame.Health:WaitForChild("HealthAmount")
local PA = script.Parent.Parent.PlayerCardFrame.Attack:WaitForChild("AttackAmount")
local accuracy = script.Parent.Parent.PlayerCardFrame.Accuracy:WaitForChild("AccuracyAmount")


button.MouseButtonDown:connect(function()
	wait(0.5)
	local MissChance = math.random(1,100)
	if MissChance == 1 , accuracy.Value then
		SH.Value = PA.Value - SH.Value
	else
		print("Attack Missed!")
	end
end)

Please help me fix errors or explain to me what I need to do to fix it.

Error: 12:27:41.067 - Players.Player1.PlayerGui.BattleGui.BattleFrame.AttackButton.LocalScript:10: 'then' expected near ',' Realism Mod is running on v1.795!

It says the error is on this line; if MissChance == 1 , accuracy.Value then

2 comments

0

What is the comma supposed to represent to you? If you are using it to represent a range of numbers, then I recommend that you use "MissChance >= 1 or MissChange >=accuracy.Value" instead.

0

This article will help with reading errors: http://wiki.roblox.com/index.php?title=Lua_errors, and this one might interest you if you are making lists: https://forum.roblox.com/Forum/ShowPost.aspx?PostID=65119973

1 answer

✓ Accepted answer

I'm going to assume that you're trying to write a script that checks whether MissChance is equal to one and accuracy.Value. If this is the case, then you should use and instead. If you're trying to check whether MissChance is equal to one or accuracy.Value, then replace and with or. Below is an example of your script that should work, assuming there are no more errors in your code.

local button = script.Parent
local SH = script.Parent.Parent.NPCCardFrame.Health:WaitForChild("HealthAmount")
local PA = script.Parent.Parent.PlayerCardFrame.Attack:WaitForChild("AttackAmount")
local accuracy = script.Parent.Parent.PlayerCardFrame.Accuracy:WaitForChild("AccuracyAmount")


button.MouseButtonDown:connect(function()
    wait(0.5)
    local MissChance = math.random(1,100)
    if MissChance == 1 and accuracy.Value == 1 then
        SH.Value = PA.Value - SH.Value
    else
        print("Attack Missed!")
    end
end)

I hope this helps! Please comment any questions if you have any!

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