I want a chat message to be sent with the player and the item’s name rolled whenever a player rolls a specific item in my crate system.
The issue is that the chat message can only send one of those two.
Script in ServerScriptService:
if itemname == "Item1" or "Item2" or "Item3" or "Item4" or "Item5" then
game.ReplicatedStorage.ItemRolled:FireAllClients(player.Name, itemname)
else
end
-- itemname = rolled item name
LocalScript in StarterGui:
game.ReplicatedStorage.ItemRolled.OnClientEvent:Connect(function(plrName, itemname)
game.StarterGui:SetCore("ChatMakeSystemMessage", {
Text = plrName .. " has rolled a ".. itemname"!",
Color = Color3.fromRGB(255, 255, 255),
Font = Enum.Font.SourceSansBold,
TextSize = 18,
})
end)
I get this error when I try using these scripts:
How do I make a proper version with both plrName and itemname working?
The problem should lie with this line here:
if itemname == "Item1" or "Item2" or "Item3" or "Item4" or "Item5" then
Your first expression is just fine. However, if that one evaluates to false, then the next one proceeds to get tested. But since the string itself is the only thing in the other expressions, they’ll always evaluate to true. (you’re not comparing them to itemname
as in your first condition, so it’ll always fire the remote even if the item name wasn’t one of the 5.)
It also seems you missed the ellipsis after itemname
here:
Text = plrName .. " has rolled a ".. itemname"!",
The ..
is used to concatenate (or combine) strings together. The compiler thinks you’re trying to call a function supplying the !
string as a parameter to it.
2 Likes
I used your fixes by adding:
else
end
to the first script, and I updated the line on the second script, but I am still getting the same error.
If you’re still getting the same error you need to change this line:
Text = plrName .. " has rolled a ".. itemname"!",
to
Text = plrName .. " has rolled a ".. itemname.."!"