Just a question for my scriptinghelpers community (awesome community everybody is so helpful and nice). So, personally I would say this is more of a personal preference but, I do know for a fact there is always a better way to do something. So I'm going to provide a code below that works that I wrote to award a badge on touch. I was wondering if there was a better way to do this, more effective if you will. Maybe not as easy to like break or be exploited (don't think it would be but still a thought I always consider nowadays you never know what people will exploit). Very simply script, basic stuff right here everybody learns at the start I would say. Important but basic. So I was wondering if there is anything I'm maybe missing out on, or you know whatever. I can't wait to hear your feedback! Thank you for the responses in advance, every productive response will receive an upvote and, I'll be selecting the answer to the question with the most help versus the best code. Like I said thanks again, this is 100% just for fun, I'm looking for opinions.
local BadgeId = 2124749339 script.Parent.Touched:Connect(function(hit) if hit.Parent == nil then return end local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player == nil then return end game:GetService("BadgeService"):AwardBadge(player.UserId, BadgeId) end)
it’s completely fine, not much more you can do for like seven lines. if you wanted to get really nitpicky there are two things I would have done differently.
BadgeId
as BADGE_ID
. it makes it obvious that it was not calculated somewhere, but specifically set by the developer. you should also put them around the top of the script next to the requires and stuff so you can change them easily, not inside of functions or in the middle of the script.