PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Admin Command Module: Code Sample 8

Admin Command Module: Code Sample 8

Sep 30 2018, 8:27 AM PST

-- Gives a specified player's character sparkles
function sparklesCommand(commandData)
	 -- Error if no parameters are given/spoken
	if #commandData.Parameters == 0 then
		return Utilities:NoPlayerSpecified(commandData)
	end
	-- Loop through the parameters (execute on every given player's name)
	for index = 1, #commandData.Parameters do
		local parameter = commandData.Parameters[index]
		if (parameter == "me" or parameter == "") then parameter = commandData.Speaker.Name end -- If the parameter is me then the user must be refering to his/herself
	
		-- Use a helper function to find the player's character and add the sparkles
		local character = Utilities:GetCharacter(parameter)
		if character then
			local sparkles = Instance.new("Sparkles")
			sparkles.Parent = character:FindFirstChild("HumanoidRootPart")
			
			Utilities:SendSystemSuccessMessage(commandData, string.format(commandData.Speaker.Name .. "added sparkles to " .. parameter))
		else
			Utilities:SendSystemErrorMessage(commandData, string.format("'s' is not a valid player.", parameter))
			return false
		end
	end	
	return true

end

AdminCommands:BindCommand({"sparkles"}, sparklesCommand, 1, "Gives the specified player sparkles")